Submission #00183


ソースコード

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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;
const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;
vector< int > Div( int n ) {
vector< int > ret;
for( int i = 1; i * i <= n; ++i ) {
if( n % i ) {
ret.pb( i );
if( i * i != n ) ret.pb( n / i );
}
}
sort( all( ret ) );
return ret;
}
int Root( int x, int cl );
bool Unite( int x, int y );
int root[SIZE];
int club[SIZE];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
for( int i = 0; i < SIZE; ++i ) { root[i] = i; club[i] = -1; }
int n, m, k;
cin >> n >> m >> k;
bool flg = true;
for( int i = 1; i <= k; ++i ) {
int s, a, b;
cin >> s >> a >> b;
int ra, rb;
if( !flg ) continue;
if( s == 1 ) {
if( club[a] != club[b] && ( club[a] != -1 && club[b] != -1 ) ) {
cout << i << endl;
flg = false;
continue;
}
club[a] = club[Root(a, club[a])];
club[b] = club[Root(b, club[b])];
if( !Unite( a, b ) ) {
cout << i << endl;
flg = false;
continue;
}
if( club[a] != -1 ) club[Root(b, club[b])] = club[a];
else club[Root(a, club[a])] = club[b];
} else {
if( club[a] != b && club[a] != -1 ) {
cout << i << endl;
flg = false;
continue;
}
club[a] = b;
if( club[Root(a, club[a])] != club[a] && club[Root(a, club[a])] != -1 ) {
cout << i << endl;
flg = false;
}
club[Root(a, club[a])] = b;
}
}
if( flg ) cout << 0 << endl;
return 0;
}
int Root( int x, int cl ) {
if( cl != club[x] ) return -1;
if( x == root[x] ) return x;
return root[x] = Root( root[x], club[x] );
}
bool Unite( int x, int y ) {
int rx, ry;
rx = Root( x, club[x] );
ry = Root( y, club[y] );
if( rx == ry ) return false;
if( rx < ry ) {
root[ry] = rx;
} else {
root[rx] = ry;
}
return true;
}

ステータス

項目 データ
問題 0007 - 部活動調査
ユーザー名 †ダークネスおまる†
投稿日時 2019-09-10 18:21:58
言語 C++11
状態 Wrong Answer
得点 0
ソースコード長 2659 Byte
最大実行時間 46 ms
最大メモリ使用量 3144 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
00-sample1.in AC 23 ms 2780 KB
1
00-sample2.in AC 19 ms 2820 KB
1
00-sample3.in AC 26 ms 2736 KB
1
01_small_00.in AC 22 ms 2780 KB
1
01_small_01.in AC 22 ms 2820 KB
1
01_small_02.in AC 26 ms 2864 KB
1
02_rand_00.in AC 16 ms 2908 KB
1
02_rand_01.in AC 21 ms 2828 KB
1
02_rand_02.in WA 23 ms 3000 KB
1
02_rand_03.in AC 24 ms 2788 KB
1
02_rand_04.in WA 21 ms 2828 KB
1
02_rand_05.in AC 26 ms 3000 KB
1
02_rand_06.in AC 30 ms 3040 KB
1
02_rand_07.in AC 31 ms 2824 KB
1
02_rand_08.in WA 20 ms 2872 KB
1
02_rand_09.in AC 21 ms 2912 KB
1
02_rand_10.in AC 23 ms 2948 KB
1
02_rand_11.in AC 25 ms 2996 KB
1
02_rand_12.in AC 24 ms 3044 KB
1
02_rand_13.in AC 22 ms 2832 KB
1
02_rand_14.in AC 17 ms 2880 KB
1
02_rand_15.in AC 21 ms 2924 KB
1
02_rand_16.in AC 22 ms 2972 KB
1
02_rand_17.in AC 31 ms 3012 KB
1
02_rand_18.in WA 24 ms 3056 KB
1
02_rand_19.in AC 23 ms 3104 KB
1
02_rand_20.in AC 27 ms 3016 KB
1
02_rand_21.in WA 26 ms 2928 KB
1
02_rand_22.in AC 23 ms 2976 KB
1
03_large_00.in AC 23 ms 3020 KB
1
03_large_01.in WA 23 ms 3056 KB
1
03_large_02.in AC 22 ms 3096 KB
1
03_large_03.in WA 46 ms 3136 KB
1
04_rand_large_zero_00.in WA 40 ms 2916 KB
1
50-random00.in WA 25 ms 2956 KB
1
50-random01.in WA 28 ms 2992 KB
1
50-random02.in WA 22 ms 3028 KB
1
50-random03.in WA 26 ms 3064 KB
1
50-random04.in WA 22 ms 3104 KB
1
50-random05.in WA 25 ms 3136 KB
1
50-random06.in WA 24 ms 3052 KB
1
50-random07.in AC 21 ms 3092 KB
1
50-random08.in AC 24 ms 3000 KB
1
50-random09.in AC 29 ms 2908 KB
1
max1.in AC 30 ms 2944 KB
1
maxn1.in AC 22 ms 2984 KB
1
maxn2.in AC 24 ms 3144 KB
1
maxn3.in AC 24 ms 3060 KB
1