Submission #00377
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include<bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define fr first #define sc second #define Rep(i,n) for(int i=0;i<(n);i++) #define Rrep(i, m, n) for(int i=(m);i<(n);i++) #define All(v) v.begin(),v.end() #define Uniq(v) v.erase(unique(All(v)),v.end()) typedef pair< int , int > Pii; typedef pair< int , Pii> Pip; typedef pair<string, int > Psi; typedef vector< int > Vi; const int INF = (1<<30); const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1}; struct UnionFind { vector< int > par; int cnt; UnionFind( int size_) : par(size_, -1), cnt(size_) { } void unite( int x, int y){ if ((x = find(x)) != (y = find(y))) { if (par[y] < par[x]) swap(x, y); par[x] += par[y]; par[y] = x; cnt--; } } bool same( int x, int y){ return find(x) == find(y); } int find( int x){ return par[x] < 0 ? x : par[x] = find(par[x]); } int size( int x){ return -par[find(x)]; } int size(){ return cnt; } }; int N, M, K; const int MAX_N = 1000001; int root_student[MAX_N]; int main() { cin >> N >> M >> K; int ans = -1; UnionFind u(MAX_N); for ( int i=0; i<MAX_N; i++) root_student[i] = -1; for ( int i=0; i<K; i++) { int a, b, c; b--; c--; cin >> a >> b >> c; if ( ans != -1 ) continue ; if ( a == 1 ) { if ( root_student[u.find(b)] == -1 || root_student[u.find(c)] == -1 ) { int tmp = -1; if ( root_student[u.find(b)] != -1 ) tmp = root_student[u.find(b)]; if ( root_student[u.find(c)] != -1 ) tmp = root_student[u.find(c)]; u.unite(b, c); root_student[u.find(b)] = tmp; } else if ( !u.same(b, c) || root_student[u.find(b)] != root_student[u.find(c)]) { ans = i; } } else { int tmp = u.find( b ); if ( root_student[tmp] == -1 ) { root_student[tmp] = c; } else if ( root_student[tmp] == c ) { u.unite(tmp, b); } else { ans = i; } } } cout << ans+1 << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0007 - 部活動調査 |
ユーザー名 | 椅子男 |
投稿日時 | 2016-08-29 11:56:42 |
言語 | C++11 |
状態 | Wrong Answer |
得点 | 0 |
ソースコード長 | 1995 Byte |
最大実行時間 | 123 ms |
最大メモリ使用量 | 8572 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 14 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
00-sample1.in | AC | 20 ms | 8284 KB |
1
|
00-sample2.in | AC | 18 ms | 8516 KB |
1
|
00-sample3.in | AC | 28 ms | 8368 KB |
1
|
01_small_00.in | AC | 18 ms | 8340 KB |
1
|
01_small_01.in | AC | 24 ms | 8440 KB |
1
|
01_small_02.in | AC | 22 ms | 8284 KB |
1
|
02_rand_00.in | AC | 17 ms | 8260 KB |
1
|
02_rand_01.in | AC | 27 ms | 8236 KB |
1
|
02_rand_02.in | AC | 19 ms | 8332 KB |
1
|
02_rand_03.in | AC | 19 ms | 8304 KB |
1
|
02_rand_04.in | AC | 18 ms | 8280 KB |
1
|
02_rand_05.in | AC | 19 ms | 8252 KB |
1
|
02_rand_06.in | AC | 18 ms | 8232 KB |
1
|
02_rand_07.in | AC | 23 ms | 8204 KB |
1
|
02_rand_08.in | AC | 19 ms | 8308 KB |
1
|
02_rand_09.in | AC | 21 ms | 8404 KB |
1
|
02_rand_10.in | AC | 19 ms | 8512 KB |
1
|
02_rand_11.in | AC | 21 ms | 8364 KB |
1
|
02_rand_12.in | AC | 22 ms | 8460 KB |
1
|
02_rand_13.in | AC | 22 ms | 8436 KB |
1
|
02_rand_14.in | AC | 26 ms | 8540 KB |
1
|
02_rand_15.in | AC | 21 ms | 8512 KB |
1
|
02_rand_16.in | AC | 20 ms | 8488 KB |
1
|
02_rand_17.in | AC | 23 ms | 8460 KB |
1
|
02_rand_18.in | AC | 27 ms | 8304 KB |
1
|
02_rand_19.in | AC | 21 ms | 8284 KB |
1
|
02_rand_20.in | AC | 23 ms | 8388 KB |
1
|
02_rand_21.in | AC | 21 ms | 8492 KB |
1
|
02_rand_22.in | AC | 20 ms | 8468 KB |
1
|
03_large_00.in | AC | 21 ms | 8440 KB |
1
|
03_large_01.in | AC | 30 ms | 8420 KB |
1
|
03_large_02.in | AC | 27 ms | 8396 KB |
1
|
03_large_03.in | AC | 123 ms | 8492 KB |
1
|
04_rand_large_zero_00.in | WA | 75 ms | 8344 KB |
1
|
50-random00.in | AC | 24 ms | 8312 KB |
1
|
50-random01.in | AC | 20 ms | 8416 KB |
1
|
50-random02.in | AC | 28 ms | 8520 KB |
1
|
50-random03.in | AC | 26 ms | 8496 KB |
1
|
50-random04.in | AC | 26 ms | 8472 KB |
1
|
50-random05.in | AC | 28 ms | 8440 KB |
1
|
50-random06.in | AC | 19 ms | 8420 KB |
1
|
50-random07.in | AC | 34 ms | 8520 KB |
1
|
50-random08.in | AC | 32 ms | 8496 KB |
1
|
50-random09.in | AC | 35 ms | 8468 KB |
1
|
max1.in | AC | 31 ms | 8572 KB |
1
|
maxn1.in | AC | 26 ms | 8544 KB |
1
|
maxn2.in | AC | 27 ms | 8516 KB |
1
|
maxn3.in | AC | 26 ms | 8368 KB |
1
|