#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;
#define sz(v) ((int)v.size())
#define pb push_back
#define pry cout << "YES\n"
#define prn cout << "NO\n"
#define endl '\n'
#define fst first
#define scn second
/* #define ONPC */
int n;
const int N = 1500;
int p[N];
int s[N];
int edg[N][N];
int
par(int x)
{
return p[x] = (x == p[x]) ? x : par(p[x]);
}
void
uni(int a, int b)
{
a = par(a);
b = par(b);
if (a == b) return;
if (s[a] > s[b]) swap(a,b);
for (int i = 0; i < n; ++i) {
if (i == b || i == a) continue;
edg[b][i] += edg[a][i];
edg[i][b] += edg[i][a];
}
p[a] = b;
s[b] += s[a];
return;
}
int
hasEdge(int u, int v)
{
if (u == v) return 0;
u = par(u); v = par(v);
if (u == v) return 1;
++edg[u][v];
++edg[v][u];
if (edg[u][v] == s[u] * s[v]) {
uni(u,v);
return 1;
}
return 0;
}
void
initialize(int _n)
{
n = _n;
for (int i = 0; i < n; ++i) {
p[i] = i;
s[i] = 1;
}
return;
}
#ifdef ONPC
void
solve()
{
int _n;
scanf("%d", &_n);
initialize(_n);
int a, b;
do {
printf("? ");
fflush(stdout);
scanf("%d %d", &a, &b);
printf("! %d\n", hasEdge(a,b));
} while(a^b);
}
int32_t
main(int argc, char **argv)
{
/* if (argc >= 2) { */
/* freopen(argv[1], "r", stdin); */
/* } else */
/* ios_base::sync_with_stdio(0);cin.tie(0); */
int t = 1;
/* cin >> t; */
while(t--)
solve();
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
312 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
312 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
312 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
440 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
440 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
444 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
2 ms |
696 KB |
Output is correct |
35 |
Correct |
1 ms |
612 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
708 KB |
Output is correct |
40 |
Correct |
1 ms |
564 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
1 ms |
700 KB |
Output is correct |
43 |
Correct |
1 ms |
580 KB |
Output is correct |
44 |
Correct |
1 ms |
576 KB |
Output is correct |
45 |
Correct |
2 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
704 KB |
Output is correct |
47 |
Correct |
2 ms |
596 KB |
Output is correct |
48 |
Correct |
2 ms |
596 KB |
Output is correct |
49 |
Correct |
1 ms |
700 KB |
Output is correct |
50 |
Correct |
1 ms |
708 KB |
Output is correct |
51 |
Correct |
1 ms |
596 KB |
Output is correct |
52 |
Correct |
1 ms |
700 KB |
Output is correct |
53 |
Correct |
1 ms |
596 KB |
Output is correct |
54 |
Correct |
1 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
308 KB |
Output is correct |
22 |
Correct |
0 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
308 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
440 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
588 KB |
Output is correct |
36 |
Correct |
1 ms |
716 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
1 ms |
704 KB |
Output is correct |
39 |
Correct |
2 ms |
708 KB |
Output is correct |
40 |
Correct |
1 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
708 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
1 ms |
596 KB |
Output is correct |
45 |
Correct |
1 ms |
596 KB |
Output is correct |
46 |
Correct |
2 ms |
696 KB |
Output is correct |
47 |
Correct |
1 ms |
596 KB |
Output is correct |
48 |
Correct |
1 ms |
596 KB |
Output is correct |
49 |
Correct |
1 ms |
672 KB |
Output is correct |
50 |
Correct |
1 ms |
596 KB |
Output is correct |
51 |
Correct |
2 ms |
724 KB |
Output is correct |
52 |
Correct |
1 ms |
596 KB |
Output is correct |
53 |
Correct |
2 ms |
596 KB |
Output is correct |
54 |
Correct |
1 ms |
596 KB |
Output is correct |
55 |
Correct |
34 ms |
5004 KB |
Output is correct |
56 |
Correct |
34 ms |
4976 KB |
Output is correct |
57 |
Correct |
34 ms |
4976 KB |
Output is correct |
58 |
Correct |
34 ms |
4968 KB |
Output is correct |
59 |
Correct |
38 ms |
4968 KB |
Output is correct |
60 |
Correct |
35 ms |
5048 KB |
Output is correct |
61 |
Correct |
37 ms |
4976 KB |
Output is correct |
62 |
Correct |
33 ms |
5008 KB |
Output is correct |
63 |
Correct |
36 ms |
5068 KB |
Output is correct |
64 |
Correct |
32 ms |
4056 KB |
Output is correct |
65 |
Correct |
32 ms |
4052 KB |
Output is correct |
66 |
Correct |
35 ms |
5012 KB |
Output is correct |
67 |
Correct |
36 ms |
5048 KB |
Output is correct |
68 |
Correct |
36 ms |
4992 KB |
Output is correct |
69 |
Correct |
37 ms |
5168 KB |
Output is correct |
70 |
Correct |
36 ms |
5004 KB |
Output is correct |
71 |
Correct |
33 ms |
4992 KB |
Output is correct |
72 |
Correct |
33 ms |
5068 KB |
Output is correct |
73 |
Correct |
34 ms |
5024 KB |
Output is correct |
74 |
Correct |
32 ms |
4984 KB |
Output is correct |
75 |
Correct |
33 ms |
4964 KB |
Output is correct |
76 |
Correct |
77 ms |
8888 KB |
Output is correct |
77 |
Correct |
81 ms |
8876 KB |
Output is correct |
78 |
Correct |
80 ms |
8900 KB |
Output is correct |
79 |
Correct |
80 ms |
8812 KB |
Output is correct |
80 |
Correct |
79 ms |
8912 KB |
Output is correct |
81 |
Correct |
79 ms |
8856 KB |
Output is correct |
82 |
Correct |
81 ms |
8844 KB |
Output is correct |
83 |
Correct |
77 ms |
8912 KB |
Output is correct |
84 |
Correct |
79 ms |
8812 KB |
Output is correct |
85 |
Correct |
140 ms |
13392 KB |
Output is correct |
86 |
Correct |
136 ms |
13424 KB |
Output is correct |
87 |
Correct |
140 ms |
13320 KB |
Output is correct |
88 |
Correct |
154 ms |
13372 KB |
Output is correct |
89 |
Correct |
141 ms |
13364 KB |
Output is correct |
90 |
Correct |
138 ms |
13308 KB |
Output is correct |
91 |
Correct |
137 ms |
13388 KB |
Output is correct |
92 |
Correct |
135 ms |
13388 KB |
Output is correct |
93 |
Correct |
134 ms |
13372 KB |
Output is correct |
94 |
Correct |
323 ms |
25112 KB |
Output is correct |
95 |
Correct |
325 ms |
24996 KB |
Output is correct |
96 |
Correct |
341 ms |
25064 KB |
Output is correct |
97 |
Correct |
320 ms |
25032 KB |
Output is correct |
98 |
Correct |
350 ms |
25096 KB |
Output is correct |
99 |
Correct |
328 ms |
25164 KB |
Output is correct |
100 |
Correct |
327 ms |
25036 KB |
Output is correct |