# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
137762 |
2019-07-28T09:29:00 Z |
MAMBA |
Simurgh (IOI17_simurgh) |
C++17 |
|
386 ms |
3196 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define pb push_back
typedef vector<int> vi;
const int N = 510;
struct dsu {
int par[N];
dsu() {
iota(par , par + N, 0);
}
int getPar(int v) {
return v == par[v] ? v : par[v] = getPar(par[v]);
}
inline bool merge(int a, int b) {
if ((a = getPar(a)) == (b = getPar(b))) return false;
par[a] = b;
return true;
}
};
dsu dd;
bitset<N> mark;
bitset<N * N> junk;
vi adj[N];
int dfs(int v) {
mark[v] =true;
int res = -1;
for (auto e : adj[v])
if (!mark[e]) {
res = dfs(e);
break;
}
if (res == -1) return v;
return res;
}
vi find_roads(int n, vi u, vi v) {
int m = u.size();
vi local;
while (local.size() < n - 1) {
mark.reset();
rep(i , 0 , n) adj[i].clear();
rep(i , 0 , m) {
if (junk[i]) continue;
adj[dd.getPar(u[i])].pb(dd.getPar(v[i]));
adj[dd.getPar(v[i])].pb(dd.getPar(u[i]));
}
int me = dfs(dd.getPar(0));
dsu ds;
vi ask = local;
for (auto e : ask) ds.merge(u[e] , v[e]);
rep(i , 0 , m)
if (!junk[i] && ds.getPar(u[i]) != me && ds.getPar(v[i]) != me && ds.merge(u[i] , v[i]))
ask.pb(i);
vi A, B;
rep(i , 0 , m) {
if (junk[i]) continue;
int a = ds.getPar(u[i]);
int b = ds.getPar(v[i]);
if ((a == me && b != me) || (b == me && a != me)) {
A.pb(i);
ask.pb(i);
B.pb(count_common_roads(ask));
ask.pop_back();
}
}
while (B.empty());
int res = *max_element(B.begin(), B.end());
rep(i , 0 , A.size()) {
if (B[i] == res) {
local.pb(A[i]);
dd.merge(u[A[i]] , v[A[i]]);
}
else {
junk[A[i]] = true;
}
}
}
return local;
}
Compilation message
simurgh.cpp: In function 'vi find_roads(int, vi, vi)':
simurgh.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (local.size() < n - 1) {
~~~~~~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
376 KB |
correct |
3 |
Correct |
2 ms |
376 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
348 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
376 KB |
correct |
3 |
Correct |
2 ms |
376 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
348 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
14 |
Correct |
6 ms |
376 KB |
correct |
15 |
Correct |
6 ms |
376 KB |
correct |
16 |
Correct |
7 ms |
376 KB |
correct |
17 |
Correct |
5 ms |
376 KB |
correct |
18 |
Correct |
3 ms |
376 KB |
correct |
19 |
Correct |
5 ms |
376 KB |
correct |
20 |
Correct |
5 ms |
376 KB |
correct |
21 |
Correct |
5 ms |
376 KB |
correct |
22 |
Correct |
4 ms |
376 KB |
correct |
23 |
Correct |
4 ms |
376 KB |
correct |
24 |
Correct |
4 ms |
376 KB |
correct |
25 |
Correct |
2 ms |
376 KB |
correct |
26 |
Correct |
4 ms |
376 KB |
correct |
27 |
Correct |
5 ms |
376 KB |
correct |
28 |
Correct |
3 ms |
376 KB |
correct |
29 |
Correct |
2 ms |
376 KB |
correct |
30 |
Correct |
4 ms |
380 KB |
correct |
31 |
Correct |
4 ms |
376 KB |
correct |
32 |
Correct |
4 ms |
376 KB |
correct |
33 |
Correct |
4 ms |
376 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
376 KB |
correct |
3 |
Correct |
2 ms |
376 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
348 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
14 |
Correct |
6 ms |
376 KB |
correct |
15 |
Correct |
6 ms |
376 KB |
correct |
16 |
Correct |
7 ms |
376 KB |
correct |
17 |
Correct |
5 ms |
376 KB |
correct |
18 |
Correct |
3 ms |
376 KB |
correct |
19 |
Correct |
5 ms |
376 KB |
correct |
20 |
Correct |
5 ms |
376 KB |
correct |
21 |
Correct |
5 ms |
376 KB |
correct |
22 |
Correct |
4 ms |
376 KB |
correct |
23 |
Correct |
4 ms |
376 KB |
correct |
24 |
Correct |
4 ms |
376 KB |
correct |
25 |
Correct |
2 ms |
376 KB |
correct |
26 |
Correct |
4 ms |
376 KB |
correct |
27 |
Correct |
5 ms |
376 KB |
correct |
28 |
Correct |
3 ms |
376 KB |
correct |
29 |
Correct |
2 ms |
376 KB |
correct |
30 |
Correct |
4 ms |
380 KB |
correct |
31 |
Correct |
4 ms |
376 KB |
correct |
32 |
Correct |
4 ms |
376 KB |
correct |
33 |
Correct |
4 ms |
376 KB |
correct |
34 |
Correct |
386 ms |
1692 KB |
correct |
35 |
Correct |
377 ms |
1596 KB |
correct |
36 |
Correct |
253 ms |
1400 KB |
correct |
37 |
Correct |
22 ms |
432 KB |
correct |
38 |
Correct |
353 ms |
1528 KB |
correct |
39 |
Correct |
311 ms |
1532 KB |
correct |
40 |
Correct |
273 ms |
1784 KB |
correct |
41 |
Correct |
25 ms |
1276 KB |
correct |
42 |
Correct |
338 ms |
1320 KB |
correct |
43 |
Correct |
203 ms |
1080 KB |
correct |
44 |
Correct |
169 ms |
860 KB |
correct |
45 |
Correct |
194 ms |
1024 KB |
correct |
46 |
Correct |
141 ms |
760 KB |
correct |
47 |
Correct |
68 ms |
504 KB |
correct |
48 |
Correct |
11 ms |
376 KB |
correct |
49 |
Correct |
22 ms |
376 KB |
correct |
50 |
Correct |
68 ms |
612 KB |
correct |
51 |
Correct |
201 ms |
900 KB |
correct |
52 |
Correct |
169 ms |
888 KB |
correct |
53 |
Correct |
153 ms |
896 KB |
correct |
54 |
Correct |
209 ms |
964 KB |
correct |
55 |
Correct |
179 ms |
912 KB |
correct |
56 |
Correct |
180 ms |
1016 KB |
correct |
57 |
Correct |
174 ms |
976 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
376 KB |
correct |
3 |
Incorrect |
327 ms |
3196 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
376 KB |
correct |
3 |
Correct |
2 ms |
376 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
348 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
14 |
Correct |
6 ms |
376 KB |
correct |
15 |
Correct |
6 ms |
376 KB |
correct |
16 |
Correct |
7 ms |
376 KB |
correct |
17 |
Correct |
5 ms |
376 KB |
correct |
18 |
Correct |
3 ms |
376 KB |
correct |
19 |
Correct |
5 ms |
376 KB |
correct |
20 |
Correct |
5 ms |
376 KB |
correct |
21 |
Correct |
5 ms |
376 KB |
correct |
22 |
Correct |
4 ms |
376 KB |
correct |
23 |
Correct |
4 ms |
376 KB |
correct |
24 |
Correct |
4 ms |
376 KB |
correct |
25 |
Correct |
2 ms |
376 KB |
correct |
26 |
Correct |
4 ms |
376 KB |
correct |
27 |
Correct |
5 ms |
376 KB |
correct |
28 |
Correct |
3 ms |
376 KB |
correct |
29 |
Correct |
2 ms |
376 KB |
correct |
30 |
Correct |
4 ms |
380 KB |
correct |
31 |
Correct |
4 ms |
376 KB |
correct |
32 |
Correct |
4 ms |
376 KB |
correct |
33 |
Correct |
4 ms |
376 KB |
correct |
34 |
Correct |
386 ms |
1692 KB |
correct |
35 |
Correct |
377 ms |
1596 KB |
correct |
36 |
Correct |
253 ms |
1400 KB |
correct |
37 |
Correct |
22 ms |
432 KB |
correct |
38 |
Correct |
353 ms |
1528 KB |
correct |
39 |
Correct |
311 ms |
1532 KB |
correct |
40 |
Correct |
273 ms |
1784 KB |
correct |
41 |
Correct |
25 ms |
1276 KB |
correct |
42 |
Correct |
338 ms |
1320 KB |
correct |
43 |
Correct |
203 ms |
1080 KB |
correct |
44 |
Correct |
169 ms |
860 KB |
correct |
45 |
Correct |
194 ms |
1024 KB |
correct |
46 |
Correct |
141 ms |
760 KB |
correct |
47 |
Correct |
68 ms |
504 KB |
correct |
48 |
Correct |
11 ms |
376 KB |
correct |
49 |
Correct |
22 ms |
376 KB |
correct |
50 |
Correct |
68 ms |
612 KB |
correct |
51 |
Correct |
201 ms |
900 KB |
correct |
52 |
Correct |
169 ms |
888 KB |
correct |
53 |
Correct |
153 ms |
896 KB |
correct |
54 |
Correct |
209 ms |
964 KB |
correct |
55 |
Correct |
179 ms |
912 KB |
correct |
56 |
Correct |
180 ms |
1016 KB |
correct |
57 |
Correct |
174 ms |
976 KB |
correct |
58 |
Correct |
2 ms |
376 KB |
correct |
59 |
Correct |
2 ms |
376 KB |
correct |
60 |
Incorrect |
327 ms |
3196 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |