# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
742724 |
2023-05-16T19:45:08 Z |
sidon |
Simurgh (IOI17_simurgh) |
C++17 |
|
393 ms |
8508 KB |
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
struct UFDS {
vector<int> e;
int operator()(int u) {
return e[u] < 0 ? u : e[u] = (*this)(e[u]);
}
bool operator()(int u, int v) {
u = (*this)(u), v = (*this)(v);
if(u == v) return false;
if(e[u] > e[v]) swap(u, v);
e[u] += e[v], e[v] = u;
return true;
}
UFDS(int n) { e.assign(n, -1); }
};
const int Z = 500, NE = Z * Z / 2;
int vis[Z], visE[NE], t[NE], backedgeFrom[NE];
vector<int> st;
vector<array<int, 2>> g[Z], s, h[NE], q;
vector<array<int, 3>> o;
int ask(int u, int v) {
for(int &j : st) if(j == u) j = v;
int res = count_common_roads(st);
for(int &j : st) if(j == v) j = u;
return res;
}
void dfs(int u, int p) {
vis[u] = 1;
for(auto [v, i] : g[u]) if(v != p) {
if(vis[v] == 1) {
for(int j = size(s); j--; ) {
backedgeFrom[s[j][1]] = i;
t[s[j][1]] = -1;
if(s[j][0] == v) break;
int a = s[j][1], b = s[j-1][1];
if(!visE[a]++) o.push_back({a, b, i});
}
} else if(!vis[v]) {
s.push_back({u, i});
st.push_back(i);
t[i] = 1;
dfs(v, u);
s.pop_back();
}
}
vis[u] = 2;
}
void color(int u) {
for(auto [v, w] : h[u]) if(t[v] < 0) {
t[v] = t[u] ^ w;
color(v);
}
}
vector<int> find_roads(int n, vector<int> U, vector<int> V) {
for(int i = size(U); i--; ) {
g[U[i]].push_back({V[i], i});
g[V[i]].push_back({U[i], i});
}
fill(t, t + NE, -1);
dfs(0, 0);
int def = count_common_roads(st);
for(auto [a, b, i] : o) {
int x = ask(a, i), y = ask(b, i);
h[b].push_back({a, x != y});
h[a].push_back({b, x != y});
if(x != y) q.push_back({a, x < y});
}
while(1) {
for(auto [u, w] : q) if(t[u] < 0) {
t[u] = w;
color(u);
}
q.clear();
bool done = 1;
for(int i : st) if(t[i] < 0) {
int e = backedgeFrom[i];
done = 0;
q.push_back({i, ask(i, e) < def});
}
if(done) break;
}
for(int u = 0; u < n; ++u) {
vector<int> a;
for(auto [v, i] : g[u]) if(u < v && t[i] < 0)
a.push_back(i);
while(!empty(a)) {
int x = 0;
for(int y = 1<<10; y /= 2; ) if(x + y <= (int)size(a)) {
x += y;
UFDS uf(n);
vector<int> qry;
for(int i = 0; i < x; ++i) {
uf(U[a[i]], V[a[i]]);
qry.push_back(a[i]);
}
int cnt {};
for(int e : st) if(uf(U[e], V[e])) {
qry.push_back(e);
cnt += t[e];
}
if(cnt < count_common_roads(qry)) x -= y;
}
for(int i = 0; i < x; ++i)
t[a[i]] = 0;
if(x == (int)size(a)) break;
t[a[x]] = 1;
a = vector<int> {begin(a) + x + 1, end(a)};
}
}
vector<int> res;
for(int i = size(U); i--; )
if(t[i] == 1) res.push_back(i);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
2 ms |
3668 KB |
correct |
3 |
Correct |
2 ms |
3668 KB |
correct |
4 |
Correct |
2 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
2 ms |
3636 KB |
correct |
7 |
Correct |
3 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3636 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3640 KB |
correct |
12 |
Correct |
2 ms |
3644 KB |
correct |
13 |
Correct |
2 ms |
3636 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
2 ms |
3668 KB |
correct |
3 |
Correct |
2 ms |
3668 KB |
correct |
4 |
Correct |
2 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
2 ms |
3636 KB |
correct |
7 |
Correct |
3 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3636 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3640 KB |
correct |
12 |
Correct |
2 ms |
3644 KB |
correct |
13 |
Correct |
2 ms |
3636 KB |
correct |
14 |
Correct |
5 ms |
3796 KB |
correct |
15 |
Correct |
4 ms |
3796 KB |
correct |
16 |
Correct |
3 ms |
3796 KB |
correct |
17 |
Correct |
3 ms |
3776 KB |
correct |
18 |
Correct |
3 ms |
3668 KB |
correct |
19 |
Correct |
4 ms |
3796 KB |
correct |
20 |
Correct |
3 ms |
3796 KB |
correct |
21 |
Correct |
3 ms |
3796 KB |
correct |
22 |
Correct |
3 ms |
3796 KB |
correct |
23 |
Correct |
3 ms |
3676 KB |
correct |
24 |
Correct |
3 ms |
3668 KB |
correct |
25 |
Correct |
3 ms |
3640 KB |
correct |
26 |
Correct |
4 ms |
3668 KB |
correct |
27 |
Correct |
4 ms |
3768 KB |
correct |
28 |
Correct |
3 ms |
3668 KB |
correct |
29 |
Correct |
2 ms |
3668 KB |
correct |
30 |
Correct |
3 ms |
3764 KB |
correct |
31 |
Correct |
3 ms |
3796 KB |
correct |
32 |
Correct |
3 ms |
3768 KB |
correct |
33 |
Correct |
3 ms |
3796 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
2 ms |
3668 KB |
correct |
3 |
Correct |
2 ms |
3668 KB |
correct |
4 |
Correct |
2 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
2 ms |
3636 KB |
correct |
7 |
Correct |
3 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3636 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3640 KB |
correct |
12 |
Correct |
2 ms |
3644 KB |
correct |
13 |
Correct |
2 ms |
3636 KB |
correct |
14 |
Correct |
5 ms |
3796 KB |
correct |
15 |
Correct |
4 ms |
3796 KB |
correct |
16 |
Correct |
3 ms |
3796 KB |
correct |
17 |
Correct |
3 ms |
3776 KB |
correct |
18 |
Correct |
3 ms |
3668 KB |
correct |
19 |
Correct |
4 ms |
3796 KB |
correct |
20 |
Correct |
3 ms |
3796 KB |
correct |
21 |
Correct |
3 ms |
3796 KB |
correct |
22 |
Correct |
3 ms |
3796 KB |
correct |
23 |
Correct |
3 ms |
3676 KB |
correct |
24 |
Correct |
3 ms |
3668 KB |
correct |
25 |
Correct |
3 ms |
3640 KB |
correct |
26 |
Correct |
4 ms |
3668 KB |
correct |
27 |
Correct |
4 ms |
3768 KB |
correct |
28 |
Correct |
3 ms |
3668 KB |
correct |
29 |
Correct |
2 ms |
3668 KB |
correct |
30 |
Correct |
3 ms |
3764 KB |
correct |
31 |
Correct |
3 ms |
3796 KB |
correct |
32 |
Correct |
3 ms |
3768 KB |
correct |
33 |
Correct |
3 ms |
3796 KB |
correct |
34 |
Correct |
52 ms |
5076 KB |
correct |
35 |
Correct |
60 ms |
5036 KB |
correct |
36 |
Correct |
46 ms |
4912 KB |
correct |
37 |
Correct |
10 ms |
3796 KB |
correct |
38 |
Correct |
58 ms |
4948 KB |
correct |
39 |
Correct |
53 ms |
4948 KB |
correct |
40 |
Correct |
48 ms |
4920 KB |
correct |
41 |
Correct |
61 ms |
4960 KB |
correct |
42 |
Correct |
56 ms |
5076 KB |
correct |
43 |
Correct |
25 ms |
4564 KB |
correct |
44 |
Correct |
22 ms |
4308 KB |
correct |
45 |
Correct |
25 ms |
4436 KB |
correct |
46 |
Correct |
20 ms |
4420 KB |
correct |
47 |
Correct |
14 ms |
4040 KB |
correct |
48 |
Correct |
5 ms |
3796 KB |
correct |
49 |
Correct |
9 ms |
3772 KB |
correct |
50 |
Correct |
12 ms |
4052 KB |
correct |
51 |
Correct |
24 ms |
4360 KB |
correct |
52 |
Correct |
20 ms |
4308 KB |
correct |
53 |
Correct |
19 ms |
4308 KB |
correct |
54 |
Correct |
26 ms |
4564 KB |
correct |
55 |
Correct |
23 ms |
4420 KB |
correct |
56 |
Correct |
24 ms |
4436 KB |
correct |
57 |
Correct |
28 ms |
4436 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
2 ms |
3668 KB |
correct |
3 |
Correct |
216 ms |
7272 KB |
correct |
4 |
Correct |
390 ms |
8396 KB |
correct |
5 |
Correct |
393 ms |
8508 KB |
correct |
6 |
Correct |
382 ms |
8500 KB |
correct |
7 |
Correct |
359 ms |
8248 KB |
correct |
8 |
Correct |
367 ms |
8076 KB |
correct |
9 |
Correct |
376 ms |
8300 KB |
correct |
10 |
Correct |
346 ms |
8328 KB |
correct |
11 |
Correct |
382 ms |
8192 KB |
correct |
12 |
Correct |
385 ms |
8160 KB |
correct |
13 |
Correct |
2 ms |
3668 KB |
correct |
14 |
Correct |
387 ms |
8204 KB |
correct |
15 |
Correct |
359 ms |
8208 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
2 ms |
3668 KB |
correct |
3 |
Correct |
2 ms |
3668 KB |
correct |
4 |
Correct |
2 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
2 ms |
3636 KB |
correct |
7 |
Correct |
3 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3636 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3640 KB |
correct |
12 |
Correct |
2 ms |
3644 KB |
correct |
13 |
Correct |
2 ms |
3636 KB |
correct |
14 |
Correct |
5 ms |
3796 KB |
correct |
15 |
Correct |
4 ms |
3796 KB |
correct |
16 |
Correct |
3 ms |
3796 KB |
correct |
17 |
Correct |
3 ms |
3776 KB |
correct |
18 |
Correct |
3 ms |
3668 KB |
correct |
19 |
Correct |
4 ms |
3796 KB |
correct |
20 |
Correct |
3 ms |
3796 KB |
correct |
21 |
Correct |
3 ms |
3796 KB |
correct |
22 |
Correct |
3 ms |
3796 KB |
correct |
23 |
Correct |
3 ms |
3676 KB |
correct |
24 |
Correct |
3 ms |
3668 KB |
correct |
25 |
Correct |
3 ms |
3640 KB |
correct |
26 |
Correct |
4 ms |
3668 KB |
correct |
27 |
Correct |
4 ms |
3768 KB |
correct |
28 |
Correct |
3 ms |
3668 KB |
correct |
29 |
Correct |
2 ms |
3668 KB |
correct |
30 |
Correct |
3 ms |
3764 KB |
correct |
31 |
Correct |
3 ms |
3796 KB |
correct |
32 |
Correct |
3 ms |
3768 KB |
correct |
33 |
Correct |
3 ms |
3796 KB |
correct |
34 |
Correct |
52 ms |
5076 KB |
correct |
35 |
Correct |
60 ms |
5036 KB |
correct |
36 |
Correct |
46 ms |
4912 KB |
correct |
37 |
Correct |
10 ms |
3796 KB |
correct |
38 |
Correct |
58 ms |
4948 KB |
correct |
39 |
Correct |
53 ms |
4948 KB |
correct |
40 |
Correct |
48 ms |
4920 KB |
correct |
41 |
Correct |
61 ms |
4960 KB |
correct |
42 |
Correct |
56 ms |
5076 KB |
correct |
43 |
Correct |
25 ms |
4564 KB |
correct |
44 |
Correct |
22 ms |
4308 KB |
correct |
45 |
Correct |
25 ms |
4436 KB |
correct |
46 |
Correct |
20 ms |
4420 KB |
correct |
47 |
Correct |
14 ms |
4040 KB |
correct |
48 |
Correct |
5 ms |
3796 KB |
correct |
49 |
Correct |
9 ms |
3772 KB |
correct |
50 |
Correct |
12 ms |
4052 KB |
correct |
51 |
Correct |
24 ms |
4360 KB |
correct |
52 |
Correct |
20 ms |
4308 KB |
correct |
53 |
Correct |
19 ms |
4308 KB |
correct |
54 |
Correct |
26 ms |
4564 KB |
correct |
55 |
Correct |
23 ms |
4420 KB |
correct |
56 |
Correct |
24 ms |
4436 KB |
correct |
57 |
Correct |
28 ms |
4436 KB |
correct |
58 |
Correct |
2 ms |
3668 KB |
correct |
59 |
Correct |
2 ms |
3668 KB |
correct |
60 |
Correct |
216 ms |
7272 KB |
correct |
61 |
Correct |
390 ms |
8396 KB |
correct |
62 |
Correct |
393 ms |
8508 KB |
correct |
63 |
Correct |
382 ms |
8500 KB |
correct |
64 |
Correct |
359 ms |
8248 KB |
correct |
65 |
Correct |
367 ms |
8076 KB |
correct |
66 |
Correct |
376 ms |
8300 KB |
correct |
67 |
Correct |
346 ms |
8328 KB |
correct |
68 |
Correct |
382 ms |
8192 KB |
correct |
69 |
Correct |
385 ms |
8160 KB |
correct |
70 |
Correct |
2 ms |
3668 KB |
correct |
71 |
Correct |
387 ms |
8204 KB |
correct |
72 |
Correct |
359 ms |
8208 KB |
correct |
73 |
Correct |
2 ms |
3668 KB |
correct |
74 |
Correct |
371 ms |
8268 KB |
correct |
75 |
Correct |
344 ms |
8136 KB |
correct |
76 |
Correct |
142 ms |
5532 KB |
correct |
77 |
Correct |
364 ms |
8208 KB |
correct |
78 |
Correct |
383 ms |
8080 KB |
correct |
79 |
Correct |
373 ms |
8184 KB |
correct |
80 |
Correct |
373 ms |
8160 KB |
correct |
81 |
Correct |
310 ms |
7872 KB |
correct |
82 |
Correct |
363 ms |
8168 KB |
correct |
83 |
Correct |
228 ms |
6404 KB |
correct |
84 |
Correct |
178 ms |
7032 KB |
correct |
85 |
Correct |
123 ms |
6740 KB |
correct |
86 |
Correct |
101 ms |
5660 KB |
correct |
87 |
Correct |
81 ms |
5440 KB |
correct |
88 |
Correct |
60 ms |
4896 KB |
correct |
89 |
Correct |
72 ms |
4816 KB |
correct |
90 |
Correct |
69 ms |
4760 KB |
correct |
91 |
Correct |
32 ms |
3924 KB |
correct |
92 |
Correct |
14 ms |
3796 KB |
correct |
93 |
Correct |
142 ms |
6756 KB |
correct |
94 |
Correct |
97 ms |
5632 KB |
correct |
95 |
Correct |
99 ms |
5748 KB |
correct |
96 |
Correct |
61 ms |
4824 KB |
correct |
97 |
Correct |
69 ms |
4892 KB |
correct |
98 |
Correct |
77 ms |
5384 KB |
correct |
99 |
Correct |
66 ms |
4852 KB |
correct |
100 |
Correct |
42 ms |
4092 KB |
correct |
101 |
Correct |
18 ms |
3864 KB |
correct |
102 |
Correct |
128 ms |
6112 KB |
correct |
103 |
Correct |
156 ms |
6068 KB |
correct |
104 |
Correct |
157 ms |
6128 KB |
correct |
105 |
Correct |
135 ms |
6116 KB |
correct |