# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
293108 |
2020-09-07T16:27:09 Z |
Saboon |
Simurgh (IOI17_simurgh) |
C++17 |
|
186 ms |
7672 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 10;
vector<pair<int,int>> g[maxn];
int par[maxn], parindex[maxn], h[maxn];
bool visited[maxn];
int Cost, c[maxn*maxn];
void dfs(int v){
visited[v] = 1;
for (auto [u,idx] : g[v]){
if (!visited[u]){
h[u] = h[v]+1;
par[u] = v;
parindex[u] = idx;
dfs(u);
}
}
}
bool eq[maxn];
vector<int> Q;
vector<int> Dw[maxn];
vector<int> Ed[maxn];
int sz[maxn];
int Ask(int l, int r, int x){
int AllZero = Cost;
for (int i = l; i < r; i++){
Q[Dw[x][i]-1] = Ed[x][i];
AllZero -= c[parindex[Dw[x][i]]];
}
int Tmp = count_common_roads(Q);
for (int i = l; i < r; i++)
Q[Dw[x][i]-1] = parindex[Dw[x][i]];
return Tmp-AllZero;
}
void solve(int l, int r, int x, int cnt){
if (l >= r)
return;
if (l+1 == r){
c[Ed[x][l]] = 1;
return;
}
int mid = (l+r) >> 1;
int t = Ask(l, mid, x);
if (t > 0)
solve(l,mid,x,t);
if (t < cnt)
solve(mid,r,x,cnt-t);
}
vector<int> find_roads(int n, vector<int> u, vector<int> v){
int m = v.size();
for (int i = 0; i < v.size(); i++){
g[v[i]].push_back({u[i],i});
g[u[i]].push_back({v[i],i});
}
dfs(0);
Q.resize(n-1);
for (int i = 1; i < n; i++)
Q[i-1] = parindex[i];
Cost = count_common_roads(Q);
memset(c, -1, sizeof c);
for (int i = 0; i < m; i++){
if (h[v[i]] > h[u[i]])
swap(v[i],u[i]);
if (par[u[i]] == v[i])
continue;
int x = u[i], found = 0, me = -1;
while (x != v[i]){
if (c[parindex[x]] == -1)
found = 1;
x = par[x];
}
if (!found)
continue;
x = u[i];
while (x != v[i]){
if (c[parindex[x]] != -1 and me != -1){
x = par[x];
continue;
}
Q[x-1] = i;
int Tmp = count_common_roads(Q);
if (c[parindex[x]] != -1){
if (Tmp == Cost)
me = c[parindex[x]];
else
me = 1-c[parindex[x]];
}
else{
if (Tmp == Cost)
eq[x] = 1;
else if (Tmp > Cost)
eq[x] = 0, me = 1;
else
eq[x] = 0, me = 0;
}
Q[x-1] = parindex[x];
x = par[x];
}
if (me == -1)
me = 0;
x = u[i];
while (x != v[i]){
if (c[parindex[x]] == -1){
if (eq[x])
c[parindex[x]] = me;
else
c[parindex[x]] = 1-me;
}
x = par[x];
}
c[i] = me;
}
for (int i = 1; i < n; i++)
c[parindex[i]] = abs(c[parindex[i]]);
for (int i = 0; i < m; i++){
if (c[i] != -1)
continue;
Dw[sz[u[i]]].push_back(u[i]);
Ed[sz[u[i]]].push_back(i);
sz[u[i]] ++;
}
for (int i = 0; i < n; i++){
if (Dw[i].empty())
break;
int t = Ask(0, Dw[i].size(), i);
if (t > 0)
solve(0, Dw[i].size(), i, t);
}
int now = 0;
for (int i = 0; i < m; i++)
if (c[i] == 1)
Q[now++] = i;
return Q;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
correct |
2 |
Correct |
1 ms |
1408 KB |
correct |
3 |
Correct |
2 ms |
1408 KB |
correct |
4 |
Correct |
1 ms |
1408 KB |
correct |
5 |
Correct |
2 ms |
1408 KB |
correct |
6 |
Correct |
1 ms |
1408 KB |
correct |
7 |
Correct |
1 ms |
1408 KB |
correct |
8 |
Correct |
1 ms |
1408 KB |
correct |
9 |
Correct |
1 ms |
1408 KB |
correct |
10 |
Correct |
1 ms |
1440 KB |
correct |
11 |
Correct |
1 ms |
1408 KB |
correct |
12 |
Correct |
2 ms |
1408 KB |
correct |
13 |
Correct |
1 ms |
1408 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
correct |
2 |
Correct |
1 ms |
1408 KB |
correct |
3 |
Correct |
2 ms |
1408 KB |
correct |
4 |
Correct |
1 ms |
1408 KB |
correct |
5 |
Correct |
2 ms |
1408 KB |
correct |
6 |
Correct |
1 ms |
1408 KB |
correct |
7 |
Correct |
1 ms |
1408 KB |
correct |
8 |
Correct |
1 ms |
1408 KB |
correct |
9 |
Correct |
1 ms |
1408 KB |
correct |
10 |
Correct |
1 ms |
1440 KB |
correct |
11 |
Correct |
1 ms |
1408 KB |
correct |
12 |
Correct |
2 ms |
1408 KB |
correct |
13 |
Correct |
1 ms |
1408 KB |
correct |
14 |
Correct |
2 ms |
1408 KB |
correct |
15 |
Correct |
3 ms |
1408 KB |
correct |
16 |
Correct |
3 ms |
1408 KB |
correct |
17 |
Correct |
2 ms |
1408 KB |
correct |
18 |
Correct |
2 ms |
1408 KB |
correct |
19 |
Correct |
2 ms |
1408 KB |
correct |
20 |
Correct |
2 ms |
1408 KB |
correct |
21 |
Correct |
2 ms |
1408 KB |
correct |
22 |
Correct |
2 ms |
1408 KB |
correct |
23 |
Correct |
1 ms |
1408 KB |
correct |
24 |
Correct |
2 ms |
1408 KB |
correct |
25 |
Correct |
1 ms |
1408 KB |
correct |
26 |
Correct |
1 ms |
1408 KB |
correct |
27 |
Correct |
1 ms |
1408 KB |
correct |
28 |
Correct |
2 ms |
1408 KB |
correct |
29 |
Correct |
2 ms |
1408 KB |
correct |
30 |
Correct |
1 ms |
1408 KB |
correct |
31 |
Correct |
1 ms |
1408 KB |
correct |
32 |
Correct |
2 ms |
1408 KB |
correct |
33 |
Correct |
1 ms |
1408 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
correct |
2 |
Correct |
1 ms |
1408 KB |
correct |
3 |
Correct |
2 ms |
1408 KB |
correct |
4 |
Correct |
1 ms |
1408 KB |
correct |
5 |
Correct |
2 ms |
1408 KB |
correct |
6 |
Correct |
1 ms |
1408 KB |
correct |
7 |
Correct |
1 ms |
1408 KB |
correct |
8 |
Correct |
1 ms |
1408 KB |
correct |
9 |
Correct |
1 ms |
1408 KB |
correct |
10 |
Correct |
1 ms |
1440 KB |
correct |
11 |
Correct |
1 ms |
1408 KB |
correct |
12 |
Correct |
2 ms |
1408 KB |
correct |
13 |
Correct |
1 ms |
1408 KB |
correct |
14 |
Correct |
2 ms |
1408 KB |
correct |
15 |
Correct |
3 ms |
1408 KB |
correct |
16 |
Correct |
3 ms |
1408 KB |
correct |
17 |
Correct |
2 ms |
1408 KB |
correct |
18 |
Correct |
2 ms |
1408 KB |
correct |
19 |
Correct |
2 ms |
1408 KB |
correct |
20 |
Correct |
2 ms |
1408 KB |
correct |
21 |
Correct |
2 ms |
1408 KB |
correct |
22 |
Correct |
2 ms |
1408 KB |
correct |
23 |
Correct |
1 ms |
1408 KB |
correct |
24 |
Correct |
2 ms |
1408 KB |
correct |
25 |
Correct |
1 ms |
1408 KB |
correct |
26 |
Correct |
1 ms |
1408 KB |
correct |
27 |
Correct |
1 ms |
1408 KB |
correct |
28 |
Correct |
2 ms |
1408 KB |
correct |
29 |
Correct |
2 ms |
1408 KB |
correct |
30 |
Correct |
1 ms |
1408 KB |
correct |
31 |
Correct |
1 ms |
1408 KB |
correct |
32 |
Correct |
2 ms |
1408 KB |
correct |
33 |
Correct |
1 ms |
1408 KB |
correct |
34 |
Correct |
31 ms |
2700 KB |
correct |
35 |
Correct |
30 ms |
2560 KB |
correct |
36 |
Correct |
25 ms |
2352 KB |
correct |
37 |
Correct |
6 ms |
1408 KB |
correct |
38 |
Correct |
34 ms |
2676 KB |
correct |
39 |
Correct |
29 ms |
2560 KB |
correct |
40 |
Correct |
25 ms |
2432 KB |
correct |
41 |
Correct |
32 ms |
2688 KB |
correct |
42 |
Correct |
33 ms |
2676 KB |
correct |
43 |
Correct |
12 ms |
2176 KB |
correct |
44 |
Correct |
11 ms |
1920 KB |
correct |
45 |
Correct |
11 ms |
2048 KB |
correct |
46 |
Correct |
11 ms |
1920 KB |
correct |
47 |
Correct |
6 ms |
1664 KB |
correct |
48 |
Correct |
3 ms |
1408 KB |
correct |
49 |
Correct |
4 ms |
1408 KB |
correct |
50 |
Correct |
6 ms |
1664 KB |
correct |
51 |
Correct |
13 ms |
2048 KB |
correct |
52 |
Correct |
10 ms |
1920 KB |
correct |
53 |
Correct |
10 ms |
1848 KB |
correct |
54 |
Correct |
12 ms |
2176 KB |
correct |
55 |
Correct |
14 ms |
2048 KB |
correct |
56 |
Correct |
12 ms |
2048 KB |
correct |
57 |
Correct |
13 ms |
2048 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
correct |
2 |
Correct |
1 ms |
1408 KB |
correct |
3 |
Correct |
100 ms |
5224 KB |
correct |
4 |
Correct |
180 ms |
6764 KB |
correct |
5 |
Correct |
186 ms |
6776 KB |
correct |
6 |
Correct |
185 ms |
6776 KB |
correct |
7 |
Correct |
174 ms |
6788 KB |
correct |
8 |
Correct |
169 ms |
6780 KB |
correct |
9 |
Correct |
167 ms |
6776 KB |
correct |
10 |
Correct |
173 ms |
6676 KB |
correct |
11 |
Correct |
164 ms |
6904 KB |
correct |
12 |
Correct |
162 ms |
6776 KB |
correct |
13 |
Correct |
1 ms |
1408 KB |
correct |
14 |
Correct |
161 ms |
6776 KB |
correct |
15 |
Correct |
166 ms |
6776 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
correct |
2 |
Correct |
1 ms |
1408 KB |
correct |
3 |
Correct |
2 ms |
1408 KB |
correct |
4 |
Correct |
1 ms |
1408 KB |
correct |
5 |
Correct |
2 ms |
1408 KB |
correct |
6 |
Correct |
1 ms |
1408 KB |
correct |
7 |
Correct |
1 ms |
1408 KB |
correct |
8 |
Correct |
1 ms |
1408 KB |
correct |
9 |
Correct |
1 ms |
1408 KB |
correct |
10 |
Correct |
1 ms |
1440 KB |
correct |
11 |
Correct |
1 ms |
1408 KB |
correct |
12 |
Correct |
2 ms |
1408 KB |
correct |
13 |
Correct |
1 ms |
1408 KB |
correct |
14 |
Correct |
2 ms |
1408 KB |
correct |
15 |
Correct |
3 ms |
1408 KB |
correct |
16 |
Correct |
3 ms |
1408 KB |
correct |
17 |
Correct |
2 ms |
1408 KB |
correct |
18 |
Correct |
2 ms |
1408 KB |
correct |
19 |
Correct |
2 ms |
1408 KB |
correct |
20 |
Correct |
2 ms |
1408 KB |
correct |
21 |
Correct |
2 ms |
1408 KB |
correct |
22 |
Correct |
2 ms |
1408 KB |
correct |
23 |
Correct |
1 ms |
1408 KB |
correct |
24 |
Correct |
2 ms |
1408 KB |
correct |
25 |
Correct |
1 ms |
1408 KB |
correct |
26 |
Correct |
1 ms |
1408 KB |
correct |
27 |
Correct |
1 ms |
1408 KB |
correct |
28 |
Correct |
2 ms |
1408 KB |
correct |
29 |
Correct |
2 ms |
1408 KB |
correct |
30 |
Correct |
1 ms |
1408 KB |
correct |
31 |
Correct |
1 ms |
1408 KB |
correct |
32 |
Correct |
2 ms |
1408 KB |
correct |
33 |
Correct |
1 ms |
1408 KB |
correct |
34 |
Correct |
31 ms |
2700 KB |
correct |
35 |
Correct |
30 ms |
2560 KB |
correct |
36 |
Correct |
25 ms |
2352 KB |
correct |
37 |
Correct |
6 ms |
1408 KB |
correct |
38 |
Correct |
34 ms |
2676 KB |
correct |
39 |
Correct |
29 ms |
2560 KB |
correct |
40 |
Correct |
25 ms |
2432 KB |
correct |
41 |
Correct |
32 ms |
2688 KB |
correct |
42 |
Correct |
33 ms |
2676 KB |
correct |
43 |
Correct |
12 ms |
2176 KB |
correct |
44 |
Correct |
11 ms |
1920 KB |
correct |
45 |
Correct |
11 ms |
2048 KB |
correct |
46 |
Correct |
11 ms |
1920 KB |
correct |
47 |
Correct |
6 ms |
1664 KB |
correct |
48 |
Correct |
3 ms |
1408 KB |
correct |
49 |
Correct |
4 ms |
1408 KB |
correct |
50 |
Correct |
6 ms |
1664 KB |
correct |
51 |
Correct |
13 ms |
2048 KB |
correct |
52 |
Correct |
10 ms |
1920 KB |
correct |
53 |
Correct |
10 ms |
1848 KB |
correct |
54 |
Correct |
12 ms |
2176 KB |
correct |
55 |
Correct |
14 ms |
2048 KB |
correct |
56 |
Correct |
12 ms |
2048 KB |
correct |
57 |
Correct |
13 ms |
2048 KB |
correct |
58 |
Correct |
1 ms |
1408 KB |
correct |
59 |
Correct |
1 ms |
1408 KB |
correct |
60 |
Correct |
100 ms |
5224 KB |
correct |
61 |
Correct |
180 ms |
6764 KB |
correct |
62 |
Correct |
186 ms |
6776 KB |
correct |
63 |
Correct |
185 ms |
6776 KB |
correct |
64 |
Correct |
174 ms |
6788 KB |
correct |
65 |
Correct |
169 ms |
6780 KB |
correct |
66 |
Correct |
167 ms |
6776 KB |
correct |
67 |
Correct |
173 ms |
6676 KB |
correct |
68 |
Correct |
164 ms |
6904 KB |
correct |
69 |
Correct |
162 ms |
6776 KB |
correct |
70 |
Correct |
1 ms |
1408 KB |
correct |
71 |
Correct |
161 ms |
6776 KB |
correct |
72 |
Correct |
166 ms |
6776 KB |
correct |
73 |
Correct |
1 ms |
1408 KB |
correct |
74 |
Correct |
168 ms |
6764 KB |
correct |
75 |
Correct |
166 ms |
7544 KB |
correct |
76 |
Correct |
67 ms |
3704 KB |
correct |
77 |
Correct |
167 ms |
7652 KB |
correct |
78 |
Correct |
163 ms |
7672 KB |
correct |
79 |
Correct |
164 ms |
7672 KB |
correct |
80 |
Correct |
161 ms |
7548 KB |
correct |
81 |
Correct |
142 ms |
6904 KB |
correct |
82 |
Correct |
158 ms |
7544 KB |
correct |
83 |
Correct |
106 ms |
4816 KB |
correct |
84 |
Correct |
65 ms |
5628 KB |
correct |
85 |
Correct |
57 ms |
5240 KB |
correct |
86 |
Correct |
39 ms |
3832 KB |
correct |
87 |
Correct |
29 ms |
3328 KB |
correct |
88 |
Correct |
25 ms |
2816 KB |
correct |
89 |
Correct |
24 ms |
2688 KB |
correct |
90 |
Correct |
21 ms |
2560 KB |
correct |
91 |
Correct |
10 ms |
1664 KB |
correct |
92 |
Correct |
7 ms |
1408 KB |
correct |
93 |
Correct |
56 ms |
5240 KB |
correct |
94 |
Correct |
38 ms |
3832 KB |
correct |
95 |
Correct |
36 ms |
3912 KB |
correct |
96 |
Correct |
22 ms |
2688 KB |
correct |
97 |
Correct |
25 ms |
2816 KB |
correct |
98 |
Correct |
30 ms |
3328 KB |
correct |
99 |
Correct |
26 ms |
2816 KB |
correct |
100 |
Correct |
13 ms |
1792 KB |
correct |
101 |
Correct |
8 ms |
1408 KB |
correct |
102 |
Correct |
63 ms |
4600 KB |
correct |
103 |
Correct |
64 ms |
4600 KB |
correct |
104 |
Correct |
64 ms |
4472 KB |
correct |
105 |
Correct |
63 ms |
4472 KB |
correct |