Submission #00006


ソースコード

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
#include<iostream>
#define UNDEFINED 0
using namespace std;
int club[100005]={UNDEFINED};
int union_find[100005];
int root(int a);
void unite(int a,int b);
int main(){
int n,m,k;
int ans=0;
cin>>n>>m>>k;
for(int i=0;i<=n;i++){
union_find[i]=i;
}
for(int i=1;i<=k;i++){
int com;
cin>>com;
if(com==1){
int a,b;
cin>>a>>b;
if(club[root(a)]!=club[root(b)]&&club[root(a)]!=UNDEFINED&&club[root(b)]!=UNDEFINED){
if(ans==0){
ans=i;
}
}else{
unite(a,b);
}
}else{
int a,x;
cin>>a>>x;
if(club[root(a)]!=x&&club[root(a)]!=UNDEFINED){
if(ans==0){
ans=i;
}
}else{
club[root(a)]=x;
}
}
}
cout<<ans<<endl;
return(0);
}
int root(int a){
if(a==union_find[a]){
return(a);
}
return(union_find[a]=root(union_find[a]));
}
void unite(int a,int b){
if(club[root(a)]!=UNDEFINED){
union_find[root(b)]=root(a);
}else{
union_find[root(a)]=root(b);
}
return;
}

ステータス

項目 データ
問題 0002 - 部活動調査
ユーザー名 ei1630
投稿日時 2018-04-24 17:00:33
言語 C++11
状態 Accepted
得点 10
ソースコード長 1049 Byte
最大実行時間 116 ms
最大メモリ使用量 1416 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
00-sample1.in AC 19 ms 480 KB
1
00-sample2.in AC 26 ms 452 KB
1
00-sample3.in AC 20 ms 424 KB
1
01_small_00.in AC 17 ms 520 KB
1
01_small_01.in AC 20 ms 492 KB
1
01_small_02.in AC 19 ms 596 KB
1
02_rand_00.in AC 15 ms 444 KB
1
02_rand_01.in AC 19 ms 668 KB
1
02_rand_02.in AC 18 ms 508 KB
1
02_rand_03.in AC 18 ms 604 KB
1
02_rand_04.in AC 16 ms 572 KB
1
02_rand_05.in AC 20 ms 548 KB
1
02_rand_06.in AC 21 ms 392 KB
1
02_rand_07.in AC 17 ms 488 KB
1
02_rand_08.in AC 20 ms 460 KB
1
02_rand_09.in AC 18 ms 556 KB
1
02_rand_10.in AC 13 ms 528 KB
1
02_rand_11.in AC 18 ms 624 KB
1
02_rand_12.in AC 27 ms 596 KB
1
02_rand_13.in AC 18 ms 560 KB
1
02_rand_14.in AC 18 ms 656 KB
1
02_rand_15.in AC 22 ms 620 KB
1
02_rand_16.in AC 18 ms 588 KB
1
02_rand_17.in AC 25 ms 556 KB
1
02_rand_18.in AC 18 ms 520 KB
1
02_rand_19.in AC 18 ms 616 KB
1
02_rand_20.in AC 16 ms 708 KB
1
02_rand_21.in AC 23 ms 676 KB
1
02_rand_22.in AC 20 ms 768 KB
1
03_large_00.in AC 18 ms 612 KB
1
03_large_01.in AC 21 ms 704 KB
1
03_large_02.in AC 22 ms 760 KB
1
03_large_03.in AC 116 ms 1416 KB
1
04_rand_large_zero_00.in AC 68 ms 1372 KB
1
50-random00.in AC 20 ms 700 KB
1
50-random01.in AC 18 ms 800 KB
1
50-random02.in AC 26 ms 612 KB
1
50-random03.in AC 26 ms 668 KB
1
50-random04.in AC 26 ms 704 KB
1
50-random05.in AC 28 ms 668 KB
1
50-random06.in AC 23 ms 752 KB
1
50-random07.in AC 22 ms 772 KB
1
50-random08.in AC 24 ms 604 KB
1
50-random09.in AC 22 ms 668 KB
1
max1.in AC 26 ms 704 KB
1
maxn1.in AC 31 ms 852 KB
1
maxn2.in AC 21 ms 896 KB
1
maxn3.in AC 23 ms 936 KB
1