# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
414624 | 2021-05-30T18:27:39 Z | dolphingarlic | Simurgh (IOI17_simurgh) | C++14 | 222 ms | 6680 KB |
#include "simurgh.h" #include <bits/stdc++.h> using namespace std;int n,m,u[124750],v[124750];vector<pair<int,int>> g[500];int tin[500],low[500],timer = 0,deg[500],cmp[500];bool V[500],K[124750],G[124750];pair<int,int> B[500],par[500];vector<int> D;void d(int node = 0,int parent = -1) {V[node] = true;tin[node] = low[node] = timer++;for (pair<int,int> i : g[node]) if (i.first != parent) {if (V[i.first]) {low[node] = min(low[node],tin[i.first]);if (tin[node] > tin[i.first]) {if (B[node].first == -1 || tin[B[node].first] > tin[i.first])B[node] = i;}} else {d(i.first,node);low[node] = min(low[node],low[i.first]);if (low[i.first] > tin[node])K[i.second] = G[i.second] = true;D.push_back(i.second);par[i.first] = {node,i.second};}}}int find(int A) { return cmp[A] = (A == cmp[A] ? A : find(cmp[A])); }void onion(int A,int B) { cmp[find(A)] = find(B); }int Q(vector<int> forest) {iota(cmp,cmp + n,0);for (int i : forest) onion(u[i],v[i]);int delta = 0;for (int i : D) if (find(u[i]) != find(v[i])) {delta -= G[i];forest.push_back(i);onion(u[i],v[i]);}return count_common_roads(forest) + delta;}vector<int> find_roads(int _n,vector<int> _u,vector<int> _v) {n = _n,m = _u.size();for (int i = 0; i < m; i++) {u[i] = _u[i],v[i] = _v[i];g[u[i]].push_back({v[i],i});g[v[i]].push_back({u[i],i});}fill_n(B,n,make_pair(-1,-1));d();int D_common = count_common_roads(D);for (int i = 0; i < n; i++) if (~B[i].first) {int curr = i;bool single_K = false;vector<int> unK;while (curr != B[i].first) {if (!K[par[curr].second])unK.push_back(par[curr].second);else if (!single_K) {single_K = true;unK.push_back(par[curr].second);}curr = par[curr].first;}if (unK.size() == 1) continue;vector<int> query_res;for (int j : unK) {vector<int> to_query = {B[i].second};for (int k : D) if (k != j) to_query.push_back(k);query_res.push_back(count_common_roads(to_query));}int mx = max(D_common,*max_element(query_res.begin(),query_res.end()));for (int i = 0; i < unK.size(); i++) {K[unK[i]] = true;G[unK[i]] = (query_res[i] != mx);}}queue<int> q;for (int i = 0; i < n; i++) {vector<int> to_query;for (pair<int,int> j : g[i]) to_query.push_back(j.second);deg[i] = Q(to_query);if (deg[i] == 1) q.push(i);}while (q.size()) {int curr = q.front();q.pop();if (deg[curr] != 1) continue;int l = 0,r = g[curr].size() - 1;while (l != r) {int mid = (l + r) / 2;vector<int> to_query;for (int i = l; i <= mid; i++) to_query.push_back(g[curr][i].second);if (Q(to_query)) r = mid;else l = mid + 1;}int nxt,id;tie(nxt,id) = g[curr][l];G[id] = true;deg[nxt]--;if (deg[nxt] == 1) q.push(nxt);vector<pair<int,int>> tmp;for (pair<int,int> i : g[nxt]) if (i.second != id) tmp.push_back(i);g[nxt] = tmp;}vector<int> ans;for (int i = 0; i < m; i++) if (G[i]) ans.push_back(i);return ans;}
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 316 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 320 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 316 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 320 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 3 ms | 332 KB | correct |
15 | Correct | 3 ms | 332 KB | correct |
16 | Correct | 2 ms | 332 KB | correct |
17 | Correct | 2 ms | 332 KB | correct |
18 | Correct | 2 ms | 332 KB | correct |
19 | Correct | 3 ms | 332 KB | correct |
20 | Correct | 3 ms | 412 KB | correct |
21 | Correct | 2 ms | 332 KB | correct |
22 | Correct | 2 ms | 320 KB | correct |
23 | Correct | 2 ms | 320 KB | correct |
24 | Correct | 2 ms | 332 KB | correct |
25 | Correct | 1 ms | 320 KB | correct |
26 | Correct | 2 ms | 308 KB | correct |
27 | Correct | 2 ms | 316 KB | correct |
28 | Correct | 2 ms | 332 KB | correct |
29 | Correct | 2 ms | 332 KB | correct |
30 | Correct | 2 ms | 332 KB | correct |
31 | Correct | 2 ms | 332 KB | correct |
32 | Correct | 2 ms | 320 KB | correct |
33 | Correct | 2 ms | 332 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 316 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 320 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 3 ms | 332 KB | correct |
15 | Correct | 3 ms | 332 KB | correct |
16 | Correct | 2 ms | 332 KB | correct |
17 | Correct | 2 ms | 332 KB | correct |
18 | Correct | 2 ms | 332 KB | correct |
19 | Correct | 3 ms | 332 KB | correct |
20 | Correct | 3 ms | 412 KB | correct |
21 | Correct | 2 ms | 332 KB | correct |
22 | Correct | 2 ms | 320 KB | correct |
23 | Correct | 2 ms | 320 KB | correct |
24 | Correct | 2 ms | 332 KB | correct |
25 | Correct | 1 ms | 320 KB | correct |
26 | Correct | 2 ms | 308 KB | correct |
27 | Correct | 2 ms | 316 KB | correct |
28 | Correct | 2 ms | 332 KB | correct |
29 | Correct | 2 ms | 332 KB | correct |
30 | Correct | 2 ms | 332 KB | correct |
31 | Correct | 2 ms | 332 KB | correct |
32 | Correct | 2 ms | 320 KB | correct |
33 | Correct | 2 ms | 332 KB | correct |
34 | Correct | 42 ms | 1740 KB | correct |
35 | Correct | 42 ms | 1800 KB | correct |
36 | Correct | 38 ms | 1488 KB | correct |
37 | Correct | 15 ms | 452 KB | correct |
38 | Correct | 43 ms | 1808 KB | correct |
39 | Correct | 41 ms | 1640 KB | correct |
40 | Correct | 38 ms | 1528 KB | correct |
41 | Correct | 41 ms | 1840 KB | correct |
42 | Correct | 42 ms | 1836 KB | correct |
43 | Correct | 34 ms | 1228 KB | correct |
44 | Correct | 36 ms | 1004 KB | correct |
45 | Correct | 31 ms | 1108 KB | correct |
46 | Correct | 29 ms | 844 KB | correct |
47 | Correct | 23 ms | 588 KB | correct |
48 | Correct | 8 ms | 332 KB | correct |
49 | Correct | 17 ms | 332 KB | correct |
50 | Correct | 24 ms | 652 KB | correct |
51 | Correct | 31 ms | 1100 KB | correct |
52 | Correct | 32 ms | 1012 KB | correct |
53 | Correct | 30 ms | 972 KB | correct |
54 | Correct | 33 ms | 1228 KB | correct |
55 | Correct | 33 ms | 1100 KB | correct |
56 | Correct | 33 ms | 1104 KB | correct |
57 | Correct | 35 ms | 1120 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 127 ms | 4472 KB | correct |
4 | Correct | 195 ms | 5936 KB | correct |
5 | Correct | 202 ms | 5956 KB | correct |
6 | Correct | 201 ms | 5944 KB | correct |
7 | Correct | 203 ms | 6016 KB | correct |
8 | Correct | 220 ms | 6012 KB | correct |
9 | Correct | 214 ms | 6032 KB | correct |
10 | Correct | 205 ms | 5936 KB | correct |
11 | Correct | 201 ms | 6036 KB | correct |
12 | Correct | 205 ms | 6132 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 200 ms | 5940 KB | correct |
15 | Correct | 205 ms | 6080 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 316 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 320 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 3 ms | 332 KB | correct |
15 | Correct | 3 ms | 332 KB | correct |
16 | Correct | 2 ms | 332 KB | correct |
17 | Correct | 2 ms | 332 KB | correct |
18 | Correct | 2 ms | 332 KB | correct |
19 | Correct | 3 ms | 332 KB | correct |
20 | Correct | 3 ms | 412 KB | correct |
21 | Correct | 2 ms | 332 KB | correct |
22 | Correct | 2 ms | 320 KB | correct |
23 | Correct | 2 ms | 320 KB | correct |
24 | Correct | 2 ms | 332 KB | correct |
25 | Correct | 1 ms | 320 KB | correct |
26 | Correct | 2 ms | 308 KB | correct |
27 | Correct | 2 ms | 316 KB | correct |
28 | Correct | 2 ms | 332 KB | correct |
29 | Correct | 2 ms | 332 KB | correct |
30 | Correct | 2 ms | 332 KB | correct |
31 | Correct | 2 ms | 332 KB | correct |
32 | Correct | 2 ms | 320 KB | correct |
33 | Correct | 2 ms | 332 KB | correct |
34 | Correct | 42 ms | 1740 KB | correct |
35 | Correct | 42 ms | 1800 KB | correct |
36 | Correct | 38 ms | 1488 KB | correct |
37 | Correct | 15 ms | 452 KB | correct |
38 | Correct | 43 ms | 1808 KB | correct |
39 | Correct | 41 ms | 1640 KB | correct |
40 | Correct | 38 ms | 1528 KB | correct |
41 | Correct | 41 ms | 1840 KB | correct |
42 | Correct | 42 ms | 1836 KB | correct |
43 | Correct | 34 ms | 1228 KB | correct |
44 | Correct | 36 ms | 1004 KB | correct |
45 | Correct | 31 ms | 1108 KB | correct |
46 | Correct | 29 ms | 844 KB | correct |
47 | Correct | 23 ms | 588 KB | correct |
48 | Correct | 8 ms | 332 KB | correct |
49 | Correct | 17 ms | 332 KB | correct |
50 | Correct | 24 ms | 652 KB | correct |
51 | Correct | 31 ms | 1100 KB | correct |
52 | Correct | 32 ms | 1012 KB | correct |
53 | Correct | 30 ms | 972 KB | correct |
54 | Correct | 33 ms | 1228 KB | correct |
55 | Correct | 33 ms | 1100 KB | correct |
56 | Correct | 33 ms | 1104 KB | correct |
57 | Correct | 35 ms | 1120 KB | correct |
58 | Correct | 1 ms | 332 KB | correct |
59 | Correct | 1 ms | 332 KB | correct |
60 | Correct | 127 ms | 4472 KB | correct |
61 | Correct | 195 ms | 5936 KB | correct |
62 | Correct | 202 ms | 5956 KB | correct |
63 | Correct | 201 ms | 5944 KB | correct |
64 | Correct | 203 ms | 6016 KB | correct |
65 | Correct | 220 ms | 6012 KB | correct |
66 | Correct | 214 ms | 6032 KB | correct |
67 | Correct | 205 ms | 5936 KB | correct |
68 | Correct | 201 ms | 6036 KB | correct |
69 | Correct | 205 ms | 6132 KB | correct |
70 | Correct | 1 ms | 332 KB | correct |
71 | Correct | 200 ms | 5940 KB | correct |
72 | Correct | 205 ms | 6080 KB | correct |
73 | Correct | 1 ms | 332 KB | correct |
74 | Correct | 210 ms | 6660 KB | correct |
75 | Correct | 215 ms | 6596 KB | correct |
76 | Correct | 111 ms | 2744 KB | correct |
77 | Correct | 209 ms | 6680 KB | correct |
78 | Correct | 199 ms | 6656 KB | correct |
79 | Correct | 212 ms | 6652 KB | correct |
80 | Correct | 222 ms | 6564 KB | correct |
81 | Correct | 188 ms | 5844 KB | correct |
82 | Correct | 204 ms | 6628 KB | correct |
83 | Correct | 162 ms | 3908 KB | correct |
84 | Correct | 163 ms | 4520 KB | correct |
85 | Correct | 183 ms | 4300 KB | correct |
86 | Correct | 137 ms | 2860 KB | correct |
87 | Correct | 130 ms | 2412 KB | correct |
88 | Correct | 117 ms | 1764 KB | correct |
89 | Correct | 126 ms | 1732 KB | correct |
90 | Correct | 136 ms | 1552 KB | correct |
91 | Correct | 60 ms | 528 KB | correct |
92 | Correct | 35 ms | 332 KB | correct |
93 | Correct | 155 ms | 4284 KB | correct |
94 | Correct | 136 ms | 2876 KB | correct |
95 | Correct | 139 ms | 2880 KB | correct |
96 | Correct | 110 ms | 1620 KB | correct |
97 | Correct | 116 ms | 1764 KB | correct |
98 | Correct | 127 ms | 2420 KB | correct |
99 | Correct | 114 ms | 1772 KB | correct |
100 | Correct | 80 ms | 692 KB | correct |
101 | Correct | 35 ms | 428 KB | correct |
102 | Correct | 154 ms | 3532 KB | correct |
103 | Correct | 159 ms | 3544 KB | correct |
104 | Correct | 162 ms | 3496 KB | correct |
105 | Correct | 152 ms | 3404 KB | correct |