# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
742722 |
2023-05-16T19:30:07 Z |
sidon |
Simurgh (IOI17_simurgh) |
C++17 |
|
1320 ms |
137432 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[NE], t[NE], backedgeFrom[NE];
vector<int> st;
vector<array<int, 2>> g[Z], s, h[NE], q;
map<int, vector<int>> backedges;
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--; ) {
backedges[i].push_back(s[j][1]);
backedgeFrom[s[j][1]] = i;
t[s[j][1]] = -1;
if(s[j][0] == v) break;
}
} 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;
}
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 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);
fill(vis, vis + n, 0);
int def = count_common_roads(st);
for(auto [e, c] : backedges) {
for(int i = size(c); --i; ) if(!vis[c[i-1]]++) {
int x = ask(c[i-1], e), y = ask(c[i], e);
h[c[i]].push_back({c[i-1], x != y});
h[c[i-1]].push_back({c[i], x != y});
if(x != y) q.push_back({c[i-1], 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(backedges[e][0], 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) {
int e = a[i];
uf(U[e], V[e]);
qry.push_back(e);
}
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 |
3 ms |
3640 KB |
correct |
3 |
Correct |
3 ms |
3668 KB |
correct |
4 |
Correct |
3 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
3 ms |
3668 KB |
correct |
7 |
Correct |
2 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3668 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3668 KB |
correct |
12 |
Correct |
2 ms |
3668 KB |
correct |
13 |
Correct |
2 ms |
3668 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
3 ms |
3640 KB |
correct |
3 |
Correct |
3 ms |
3668 KB |
correct |
4 |
Correct |
3 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
3 ms |
3668 KB |
correct |
7 |
Correct |
2 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3668 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3668 KB |
correct |
12 |
Correct |
2 ms |
3668 KB |
correct |
13 |
Correct |
2 ms |
3668 KB |
correct |
14 |
Correct |
5 ms |
4052 KB |
correct |
15 |
Correct |
4 ms |
4052 KB |
correct |
16 |
Correct |
4 ms |
4052 KB |
correct |
17 |
Correct |
4 ms |
3924 KB |
correct |
18 |
Correct |
3 ms |
3796 KB |
correct |
19 |
Correct |
5 ms |
3904 KB |
correct |
20 |
Correct |
5 ms |
3924 KB |
correct |
21 |
Correct |
5 ms |
3924 KB |
correct |
22 |
Correct |
4 ms |
3796 KB |
correct |
23 |
Correct |
5 ms |
3796 KB |
correct |
24 |
Correct |
3 ms |
3796 KB |
correct |
25 |
Correct |
2 ms |
3640 KB |
correct |
26 |
Correct |
3 ms |
3796 KB |
correct |
27 |
Correct |
3 ms |
3796 KB |
correct |
28 |
Correct |
2 ms |
3796 KB |
correct |
29 |
Correct |
2 ms |
3668 KB |
correct |
30 |
Correct |
4 ms |
3772 KB |
correct |
31 |
Correct |
3 ms |
3768 KB |
correct |
32 |
Correct |
3 ms |
3796 KB |
correct |
33 |
Correct |
3 ms |
3796 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
3 ms |
3640 KB |
correct |
3 |
Correct |
3 ms |
3668 KB |
correct |
4 |
Correct |
3 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
3 ms |
3668 KB |
correct |
7 |
Correct |
2 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3668 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3668 KB |
correct |
12 |
Correct |
2 ms |
3668 KB |
correct |
13 |
Correct |
2 ms |
3668 KB |
correct |
14 |
Correct |
5 ms |
4052 KB |
correct |
15 |
Correct |
4 ms |
4052 KB |
correct |
16 |
Correct |
4 ms |
4052 KB |
correct |
17 |
Correct |
4 ms |
3924 KB |
correct |
18 |
Correct |
3 ms |
3796 KB |
correct |
19 |
Correct |
5 ms |
3904 KB |
correct |
20 |
Correct |
5 ms |
3924 KB |
correct |
21 |
Correct |
5 ms |
3924 KB |
correct |
22 |
Correct |
4 ms |
3796 KB |
correct |
23 |
Correct |
5 ms |
3796 KB |
correct |
24 |
Correct |
3 ms |
3796 KB |
correct |
25 |
Correct |
2 ms |
3640 KB |
correct |
26 |
Correct |
3 ms |
3796 KB |
correct |
27 |
Correct |
3 ms |
3796 KB |
correct |
28 |
Correct |
2 ms |
3796 KB |
correct |
29 |
Correct |
2 ms |
3668 KB |
correct |
30 |
Correct |
4 ms |
3772 KB |
correct |
31 |
Correct |
3 ms |
3768 KB |
correct |
32 |
Correct |
3 ms |
3796 KB |
correct |
33 |
Correct |
3 ms |
3796 KB |
correct |
34 |
Correct |
148 ms |
20544 KB |
correct |
35 |
Correct |
140 ms |
20056 KB |
correct |
36 |
Correct |
107 ms |
15156 KB |
correct |
37 |
Correct |
12 ms |
4308 KB |
correct |
38 |
Correct |
147 ms |
20528 KB |
correct |
39 |
Correct |
122 ms |
18100 KB |
correct |
40 |
Correct |
101 ms |
15096 KB |
correct |
41 |
Correct |
152 ms |
20556 KB |
correct |
42 |
Correct |
146 ms |
20524 KB |
correct |
43 |
Correct |
62 ms |
9756 KB |
correct |
44 |
Correct |
50 ms |
7884 KB |
correct |
45 |
Correct |
52 ms |
8948 KB |
correct |
46 |
Correct |
38 ms |
7120 KB |
correct |
47 |
Correct |
20 ms |
4808 KB |
correct |
48 |
Correct |
6 ms |
3796 KB |
correct |
49 |
Correct |
13 ms |
3988 KB |
correct |
50 |
Correct |
19 ms |
4820 KB |
correct |
51 |
Correct |
52 ms |
8924 KB |
correct |
52 |
Correct |
46 ms |
8088 KB |
correct |
53 |
Correct |
36 ms |
7188 KB |
correct |
54 |
Correct |
58 ms |
9792 KB |
correct |
55 |
Correct |
48 ms |
9044 KB |
correct |
56 |
Correct |
61 ms |
10644 KB |
correct |
57 |
Correct |
63 ms |
11384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
3 ms |
3644 KB |
correct |
3 |
Correct |
633 ms |
75808 KB |
correct |
4 |
Correct |
1148 ms |
137232 KB |
correct |
5 |
Correct |
1149 ms |
137280 KB |
correct |
6 |
Correct |
1160 ms |
137272 KB |
correct |
7 |
Correct |
1177 ms |
137400 KB |
correct |
8 |
Correct |
1212 ms |
137304 KB |
correct |
9 |
Correct |
1237 ms |
137300 KB |
correct |
10 |
Correct |
1251 ms |
137300 KB |
correct |
11 |
Correct |
1271 ms |
137168 KB |
correct |
12 |
Correct |
1112 ms |
137312 KB |
correct |
13 |
Correct |
3 ms |
3668 KB |
correct |
14 |
Correct |
1157 ms |
137432 KB |
correct |
15 |
Correct |
1152 ms |
137340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3668 KB |
correct |
2 |
Correct |
3 ms |
3640 KB |
correct |
3 |
Correct |
3 ms |
3668 KB |
correct |
4 |
Correct |
3 ms |
3668 KB |
correct |
5 |
Correct |
2 ms |
3668 KB |
correct |
6 |
Correct |
3 ms |
3668 KB |
correct |
7 |
Correct |
2 ms |
3668 KB |
correct |
8 |
Correct |
2 ms |
3668 KB |
correct |
9 |
Correct |
2 ms |
3668 KB |
correct |
10 |
Correct |
2 ms |
3668 KB |
correct |
11 |
Correct |
2 ms |
3668 KB |
correct |
12 |
Correct |
2 ms |
3668 KB |
correct |
13 |
Correct |
2 ms |
3668 KB |
correct |
14 |
Correct |
5 ms |
4052 KB |
correct |
15 |
Correct |
4 ms |
4052 KB |
correct |
16 |
Correct |
4 ms |
4052 KB |
correct |
17 |
Correct |
4 ms |
3924 KB |
correct |
18 |
Correct |
3 ms |
3796 KB |
correct |
19 |
Correct |
5 ms |
3904 KB |
correct |
20 |
Correct |
5 ms |
3924 KB |
correct |
21 |
Correct |
5 ms |
3924 KB |
correct |
22 |
Correct |
4 ms |
3796 KB |
correct |
23 |
Correct |
5 ms |
3796 KB |
correct |
24 |
Correct |
3 ms |
3796 KB |
correct |
25 |
Correct |
2 ms |
3640 KB |
correct |
26 |
Correct |
3 ms |
3796 KB |
correct |
27 |
Correct |
3 ms |
3796 KB |
correct |
28 |
Correct |
2 ms |
3796 KB |
correct |
29 |
Correct |
2 ms |
3668 KB |
correct |
30 |
Correct |
4 ms |
3772 KB |
correct |
31 |
Correct |
3 ms |
3768 KB |
correct |
32 |
Correct |
3 ms |
3796 KB |
correct |
33 |
Correct |
3 ms |
3796 KB |
correct |
34 |
Correct |
148 ms |
20544 KB |
correct |
35 |
Correct |
140 ms |
20056 KB |
correct |
36 |
Correct |
107 ms |
15156 KB |
correct |
37 |
Correct |
12 ms |
4308 KB |
correct |
38 |
Correct |
147 ms |
20528 KB |
correct |
39 |
Correct |
122 ms |
18100 KB |
correct |
40 |
Correct |
101 ms |
15096 KB |
correct |
41 |
Correct |
152 ms |
20556 KB |
correct |
42 |
Correct |
146 ms |
20524 KB |
correct |
43 |
Correct |
62 ms |
9756 KB |
correct |
44 |
Correct |
50 ms |
7884 KB |
correct |
45 |
Correct |
52 ms |
8948 KB |
correct |
46 |
Correct |
38 ms |
7120 KB |
correct |
47 |
Correct |
20 ms |
4808 KB |
correct |
48 |
Correct |
6 ms |
3796 KB |
correct |
49 |
Correct |
13 ms |
3988 KB |
correct |
50 |
Correct |
19 ms |
4820 KB |
correct |
51 |
Correct |
52 ms |
8924 KB |
correct |
52 |
Correct |
46 ms |
8088 KB |
correct |
53 |
Correct |
36 ms |
7188 KB |
correct |
54 |
Correct |
58 ms |
9792 KB |
correct |
55 |
Correct |
48 ms |
9044 KB |
correct |
56 |
Correct |
61 ms |
10644 KB |
correct |
57 |
Correct |
63 ms |
11384 KB |
correct |
58 |
Correct |
2 ms |
3668 KB |
correct |
59 |
Correct |
3 ms |
3644 KB |
correct |
60 |
Correct |
633 ms |
75808 KB |
correct |
61 |
Correct |
1148 ms |
137232 KB |
correct |
62 |
Correct |
1149 ms |
137280 KB |
correct |
63 |
Correct |
1160 ms |
137272 KB |
correct |
64 |
Correct |
1177 ms |
137400 KB |
correct |
65 |
Correct |
1212 ms |
137304 KB |
correct |
66 |
Correct |
1237 ms |
137300 KB |
correct |
67 |
Correct |
1251 ms |
137300 KB |
correct |
68 |
Correct |
1271 ms |
137168 KB |
correct |
69 |
Correct |
1112 ms |
137312 KB |
correct |
70 |
Correct |
3 ms |
3668 KB |
correct |
71 |
Correct |
1157 ms |
137432 KB |
correct |
72 |
Correct |
1152 ms |
137340 KB |
correct |
73 |
Correct |
3 ms |
3668 KB |
correct |
74 |
Correct |
1063 ms |
137188 KB |
correct |
75 |
Correct |
1208 ms |
132712 KB |
correct |
76 |
Correct |
359 ms |
43408 KB |
correct |
77 |
Correct |
1320 ms |
137192 KB |
correct |
78 |
Correct |
1288 ms |
137048 KB |
correct |
79 |
Correct |
1176 ms |
136928 KB |
correct |
80 |
Correct |
1186 ms |
132956 KB |
correct |
81 |
Correct |
1066 ms |
113776 KB |
correct |
82 |
Correct |
1137 ms |
132160 KB |
correct |
83 |
Correct |
610 ms |
69852 KB |
correct |
84 |
Correct |
501 ms |
57724 KB |
correct |
85 |
Correct |
376 ms |
45732 KB |
correct |
86 |
Correct |
234 ms |
26112 KB |
correct |
87 |
Correct |
149 ms |
15740 KB |
correct |
88 |
Correct |
115 ms |
11912 KB |
correct |
89 |
Correct |
112 ms |
11372 KB |
correct |
90 |
Correct |
89 ms |
9440 KB |
correct |
91 |
Correct |
31 ms |
4036 KB |
correct |
92 |
Correct |
14 ms |
3796 KB |
correct |
93 |
Correct |
389 ms |
45720 KB |
correct |
94 |
Correct |
223 ms |
26224 KB |
correct |
95 |
Correct |
198 ms |
23244 KB |
correct |
96 |
Correct |
85 ms |
10004 KB |
correct |
97 |
Correct |
107 ms |
11972 KB |
correct |
98 |
Correct |
140 ms |
15744 KB |
correct |
99 |
Correct |
113 ms |
12704 KB |
correct |
100 |
Correct |
43 ms |
4924 KB |
correct |
101 |
Correct |
18 ms |
3908 KB |
correct |
102 |
Correct |
357 ms |
41884 KB |
correct |
103 |
Correct |
463 ms |
59620 KB |
correct |
104 |
Correct |
492 ms |
60564 KB |
correct |
105 |
Correct |
380 ms |
44292 KB |
correct |