Submission #00197


ソースコード

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <utility>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
//#define int long long
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
struct UnionFind {
vector < pii > par;
vector < int > siz;
UnionFind(int n): par(n), siz(n, 1) { //初期化
for(int i = 1; i <= n; i++){
par[i].first = i;
par[i].second = 0;
}
}
int root(int x){ //根の更新+判定
if(par[x].first == x) return x;
else return par[x].first = root(par[x].first);
}
int size(int x){ //サイズ
return siz[root(x)];
}
bool same(int c, int x){ //グループの判定
int tmp = root(par[c].first);
if(par[tmp].second == 0){
par[tmp].second = x;
return false;
}
if(par[tmp].second == x){
return false;
}
return true;
}
bool unite(int x, int y){ //つなげる
if((x=root(x))==(y=root(y))) return false;
if( siz[y] > siz[x] ) swap(x,y);
siz[x] += siz[y];
if(par[x].second == 0 && par[y].second != 0){
par[y].first = x;
par[x].second = par[y].second;
return false;
}
else if(par[x].second != par[y].second && par[y].second != 0 && par[x].second != 0){
return true;
}
else{
par[y].first = x;
return false;
}
}
};
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m,k;
cin >> n >> m >> k;
UnionFind uf(n + 1000);
vector<int> r(k + 10), a(k + 10), b(k + 10);
reps(i, k) cin >> r[i] >> a[i] >> b[i];
reps(i,k){
if(r[i] == 1){
bool f1 = uf.unite(a[i],b[i]);
if(f1){
cout << i << '\n';
return 0;
}
}
else{
bool f1 = uf.same(a[i],b[i]);
if(f1){
cout << i << '\n';
return 0;
}
}
}
cout << 0 << '\n';
return 0;
}

ステータス

項目 データ
問題 0007 - 部活動調査
ユーザー名 虚無
投稿日時 2019-09-10 18:48:55
言語 C++14
状態 Runtime Error
得点 0
ソースコード長 2309 Byte
最大実行時間 54 ms
最大メモリ使用量 4104 KB

セット

セット 得点 Cases
1 ALL 0 / 13 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
00-sample1.in RE 49 ms 604 KB
1
00-sample2.in RE 34 ms 416 KB
1
00-sample3.in RE 34 ms 472 KB
1
01_small_00.in AC 49 ms 412 KB
1
01_small_01.in AC 23 ms 480 KB
1
01_small_02.in AC 20 ms 428 KB
1
02_rand_00.in AC 24 ms 504 KB
1
02_rand_01.in AC 21 ms 448 KB
1
02_rand_02.in RE 30 ms 396 KB
1
02_rand_03.in RE 32 ms 456 KB
1
02_rand_04.in AC 24 ms 392 KB
1
02_rand_05.in AC 25 ms 460 KB
1
02_rand_06.in AC 26 ms 408 KB
1
02_rand_07.in AC 21 ms 476 KB
1
02_rand_08.in RE 30 ms 672 KB
1
02_rand_09.in RE 30 ms 608 KB
1
02_rand_10.in AC 29 ms 544 KB
1
02_rand_11.in AC 20 ms 488 KB
1
02_rand_12.in AC 20 ms 560 KB
1
02_rand_13.in AC 24 ms 624 KB
1
02_rand_14.in AC 18 ms 556 KB
1
02_rand_15.in AC 19 ms 496 KB
1
02_rand_16.in AC 20 ms 564 KB
1
02_rand_17.in AC 20 ms 628 KB
1
02_rand_18.in AC 23 ms 564 KB
1
02_rand_19.in AC 21 ms 756 KB
1
02_rand_20.in AC 22 ms 700 KB
1
02_rand_21.in AC 23 ms 632 KB
1
02_rand_22.in AC 18 ms 568 KB
1
03_large_00.in AC 22 ms 632 KB
1
03_large_01.in AC 23 ms 804 KB
1
03_large_02.in AC 25 ms 884 KB
1
03_large_03.in AC 54 ms 4104 KB
1
04_rand_large_zero_00.in AC 40 ms 2944 KB
1
50-random00.in RE 28 ms 656 KB
1
50-random01.in RE 43 ms 660 KB
1
50-random02.in RE 29 ms 768 KB
1
50-random03.in AC 21 ms 792 KB
1
50-random04.in RE 25 ms 796 KB
1
50-random05.in RE 33 ms 864 KB
1
50-random06.in RE 31 ms 944 KB
1
50-random07.in RE 29 ms 924 KB
1
50-random08.in RE 33 ms 816 KB
1
50-random09.in AC 26 ms 1000 KB
1
max1.in AC 17 ms 1096 KB
1
maxn1.in AC 24 ms 1124 KB
1
maxn2.in AC 24 ms 840 KB
1
maxn3.in AC 20 ms 800 KB
1