Submission #2714612


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

class UnionFind {
  vector<int> data;
 public:
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
    int N,M,S; cin >>N>>M>>S;
    --S;
    vvi next(N);
    rep(i,M) {
        int u,v; cin >> u >> v;
        --u; --v;
        next[u].pb(v);
        next[v].pb(u);
    }

    vi ans;
    UnionFind uf(N);
    for (int u=N-1; u>=0; --u) {
        for (int v: next[u]) {
            if (u < v) uf.unionSet(u,v);
        }
        if (uf.root(u) == uf.root(S)) ans.pb(u);
    }
    reverse(ALL(ans));
    for (int u: ans) {
        cout << (1+u) << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task B - 駐車場
User naoya_t
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2208 Byte
Status
Exec Time 462 ms
Memory 14072 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample0.txt, sample1.txt, sample2.txt
Subtask0 40 / 40 subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, sample0.txt, sample1.txt, sample2.txt
All 60 / 60 sample0.txt, sample1.txt, sample2.txt, subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, subtask1_0.txt, subtask1_1.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt
Case Name Status Exec Time Memory
sample0.txt 1 ms 256 KB
sample1.txt 1 ms 256 KB
sample2.txt 1 ms 256 KB
subtask0_0.txt 5 ms 384 KB
subtask0_1.txt 3 ms 384 KB
subtask0_2.txt 3 ms 384 KB
subtask0_3.txt 2 ms 384 KB
subtask0_4.txt 3 ms 256 KB
subtask0_5.txt 3 ms 256 KB
subtask0_6.txt 3 ms 256 KB
subtask0_7.txt 4 ms 384 KB
subtask0_8.txt 2 ms 256 KB
subtask0_9.txt 4 ms 384 KB
subtask1_0.txt 462 ms 14072 KB
subtask1_1.txt 232 ms 7804 KB
subtask1_2.txt 234 ms 9980 KB
subtask1_3.txt 150 ms 11644 KB
subtask1_4.txt 198 ms 5500 KB
subtask1_5.txt 222 ms 6528 KB
subtask1_6.txt 305 ms 9844 KB
subtask1_7.txt 216 ms 10484 KB
subtask1_8.txt 189 ms 6136 KB
subtask1_9.txt 173 ms 8184 KB