Submission #00161


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
struct UnionFind
{
vector< int > data;
UnionFind(int sz)
{
data.assign(sz, -1);
}
void unite(int x, int y)
{
x = find(x);
y = find(y);
if(x == y) return;
data[x] += data[y];
data[y] = x;
}
int find(int k)
{
if(data[k] < 0) return (k);
return (data[k] = find(data[k]));
}
};
int main()
{
int N, M, K;
scanf("%d %d %d", &N, &M, &K);
UnionFind uf(N + M);
int check[200000];
memset(check, -1, sizeof(check));
bool error = false;
for(int i = 0; i < K; i++) {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
--y, --z;
if(x == 1) {
y = uf.find(y);
z = uf.find(z);
} else {
y = uf.find(y);
if(check[y] == -1) check[y] = z;
else if(check[y] != z) error = true;
z = uf.find(z + N);
}
if(check[y] == -1 && check[z] == -1) {
} else if(check[y] != -1 && check[z] != -1) {
if(check[y] != check[z]) error = true;
} else {
int k = max(check[y], check[z]);
check[y] = k;
check[z] = k;
}
uf.unite(y, z);
if(error) {
printf("%d\n", i + 1);
return (0);
}
}
puts("0");
}

ステータス

項目 データ
問題 0007 - 部活動調査
ユーザー名 ei1333
投稿日時 2016-08-29 10:00:20
言語 C++11
状態 Accepted
得点 14
ソースコード長 1264 Byte
最大実行時間 40 ms
最大メモリ使用量 2136 KB

セット

セット 得点 Cases
1 ALL 14 / 14 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
00-sample1.in AC 21 ms 1244 KB
1
00-sample2.in AC 27 ms 1472 KB
1
00-sample3.in AC 19 ms 1312 KB
1
01_small_00.in AC 21 ms 1280 KB
1
01_small_01.in AC 19 ms 1248 KB
1
01_small_02.in AC 20 ms 1212 KB
1
02_rand_00.in AC 24 ms 1308 KB
1
02_rand_01.in AC 16 ms 1272 KB
1
02_rand_02.in AC 16 ms 1236 KB
1
02_rand_03.in AC 18 ms 1336 KB
1
02_rand_04.in AC 23 ms 1308 KB
1
02_rand_05.in AC 13 ms 1400 KB
1
02_rand_06.in AC 20 ms 1364 KB
1
02_rand_07.in AC 22 ms 1328 KB
1
02_rand_08.in AC 20 ms 1424 KB
1
02_rand_09.in AC 26 ms 1256 KB
1
02_rand_10.in AC 23 ms 1348 KB
1
02_rand_11.in AC 17 ms 1440 KB
1
02_rand_12.in AC 20 ms 1408 KB
1
02_rand_13.in AC 19 ms 1380 KB
1
02_rand_14.in AC 18 ms 1468 KB
1
02_rand_15.in AC 25 ms 1308 KB
1
02_rand_16.in AC 16 ms 1408 KB
1
02_rand_17.in AC 17 ms 1376 KB
1
02_rand_18.in AC 22 ms 1464 KB
1
02_rand_19.in AC 21 ms 1308 KB
1
02_rand_20.in AC 18 ms 1276 KB
1
02_rand_21.in AC 24 ms 1372 KB
1
02_rand_22.in AC 17 ms 1468 KB
1
03_large_00.in AC 14 ms 1428 KB
1
03_large_01.in AC 26 ms 1504 KB
1
03_large_02.in AC 22 ms 1416 KB
1
03_large_03.in AC 18 ms 2060 KB
1
04_rand_large_zero_00.in AC 40 ms 2136 KB
1
50-random00.in AC 24 ms 1444 KB
1
50-random01.in AC 20 ms 1412 KB
1
50-random02.in AC 16 ms 1488 KB
1
50-random03.in AC 18 ms 1548 KB
1
50-random04.in AC 20 ms 1348 KB
1
50-random05.in AC 19 ms 1436 KB
1
50-random06.in AC 23 ms 1488 KB
1
50-random07.in AC 17 ms 1412 KB
1
50-random08.in AC 23 ms 1368 KB
1
50-random09.in AC 18 ms 1420 KB
1
max1.in AC 19 ms 1456 KB
1
maxn1.in AC 24 ms 1476 KB
1
maxn2.in AC 18 ms 1488 KB
1
maxn3.in AC 24 ms 1376 KB
1