# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
963636 |
2024-04-15T12:11:48 Z |
Itamar |
Simurgh (IOI17_simurgh) |
C++14 |
|
113 ms |
7516 KB |
using namespace std;
#include <vector>
#define vi vector<int>
#include "simurgh.h"
#define pi pair<int,int>
#include <random>
#define x first
#define y second
const int siz = 501;
int ans[siz][siz];
int in[siz][siz];
vi fr[siz];
int h[siz];
int pad[siz];
vi u, v;
int n;
bool vis[siz];
vi tr;
int m;
void dfs(int i) {
if (vis[i])return;
vis[i] = 1;
for (int f : fr[i]) {
if (!vis[f]) {
h[f] = h[i] + 1;
pad[f] = i;
tr.push_back(in[i][f]);
dfs(f);
}
}
}
static int find(int node, vi&parent) {
return (parent[node] == node ? node : parent[node] = find(parent[node],parent));
}
static bool merge(int v1, int v2, vi& parent, vi& siz) {
v1 = find(v1,parent);
v2 = find(v2,parent);
if (v1 == v2)
return false;
if (siz[v1] > siz[v2])swap(v1, v2);
parent[v1] = v2;
if (siz[v1] == siz[v2])siz[v2]++;
return true;
}
int common(vi ed) {
int mi = 0;
vi q = ed;
vi parent(n); for (int i = 0; i < n; i++)parent[i] = i;
vi siz(n);
for (int i : ed)merge(u[i], v[i],parent,siz);
for (int i : tr) {
if (merge(u[i], v[i], parent, siz)) {
if(ans[u[i]][v[i]]==1)mi++;
q.push_back(i);
}
}
return count_common_roads(q) - mi;
}
void check(vi ed, int f) {
if (ed.size() == 1) {
ans[u[ed[0]]][v[ed[0]]] = 1;
return;
}
int s = ed.size();
vi vec1, vec2;
for (int i = 0; i < s; i++) {
if (i < s / 2)vec1.push_back(ed[i]);
else vec2.push_back(ed[i]);
}
int h = common(vec1);
if (h>0) {
check(vec1, h);
}
if (f-h>0)check(vec2, f-h);
}
vi find_roads(int N, vi U, vi V) {
u = U, v = V;
n = N;
m = u.size();
for (int i = 0; i < m; i++) {
fr[u[i]].push_back(v[i]);
fr[v[i]].push_back(u[i]);
ans[u[i]][v[i]] = -1;
ans[v[i]][u[i]] = -1;
in[u[i]][v[i]] = i;
in[v[i]][u[i]] = i;
}
dfs(0);
int a = count_common_roads(tr);
for (int i = 0; i < n; i++) {
pi p={1e9,1e9};
for (int j : fr[i]) {
p = min(p, { h[j],j });
}
vi cyc = {in[i][p.y]};
if (p.x >= h[i] - 1)continue;
int t = i;
while (t != p.y) {
cyc.push_back({ in[t][pad[t]] });
t = pad[t];
}
vi can = { a };
vi ts(2,-1);
for (int ed : cyc) {
if (ed == cyc[0])continue;
vi q = {cyc[0]};
if (ans[u[ed]][v[ed]] != -1 && ts[ans[u[ed]][v[ed]]] != -1) {
can.push_back(ts[ans[u[ed]][v[ed]]]); continue;
}
for (int j : tr) {
if (j != ed) {
q.push_back(j);
}
}
int b = count_common_roads(q);
can.push_back(b);
if (ans[u[ed]][v[ed]] != -1)ts[ans[u[ed]][v[ed]]] = b;
}
int maxi = a;
for (int j : can)maxi = max(j, maxi);
for (int j = 0; j < can.size(); j++) {
if (can[j] < maxi) {
ans[u[cyc[j]]][v[cyc[j]]] = 1;
}
else ans[u[cyc[j]]][v[cyc[j]]] = 0;
}
}
for (int i : tr)if (ans[u[i]][v[i]] == -1)ans[u[i]][v[i]] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (ans[i][j] != -1)ans[j][i] = ans[i][j];
}
}
for (int d = 1; d < n; d++) {
vi vec;
for (int i = 0; i + d < n; i++) {
if (ans[i][i + d] == -1)vec.push_back(in[i][i + d]);
}
int h = common(vec);
if(h)check(vec,h);
}
vi res;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (ans[i][j] == 1 || ans[j][i] == 1)res.push_back(in[i][j]);
}
}
return res;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:124:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for (int j = 0; j < can.size(); j++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
704 KB |
correct |
4 |
Correct |
0 ms |
604 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
448 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
704 KB |
correct |
4 |
Correct |
0 ms |
604 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
448 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
1 ms |
604 KB |
correct |
15 |
Correct |
1 ms |
604 KB |
correct |
16 |
Correct |
1 ms |
604 KB |
correct |
17 |
Correct |
1 ms |
604 KB |
correct |
18 |
Correct |
1 ms |
604 KB |
correct |
19 |
Correct |
1 ms |
604 KB |
correct |
20 |
Correct |
1 ms |
604 KB |
correct |
21 |
Correct |
1 ms |
604 KB |
correct |
22 |
Correct |
1 ms |
452 KB |
correct |
23 |
Correct |
1 ms |
604 KB |
correct |
24 |
Correct |
1 ms |
448 KB |
correct |
25 |
Correct |
1 ms |
600 KB |
correct |
26 |
Correct |
1 ms |
604 KB |
correct |
27 |
Correct |
1 ms |
600 KB |
correct |
28 |
Correct |
1 ms |
604 KB |
correct |
29 |
Correct |
1 ms |
604 KB |
correct |
30 |
Correct |
1 ms |
604 KB |
correct |
31 |
Correct |
1 ms |
604 KB |
correct |
32 |
Correct |
1 ms |
456 KB |
correct |
33 |
Correct |
1 ms |
604 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
704 KB |
correct |
4 |
Correct |
0 ms |
604 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
448 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
1 ms |
604 KB |
correct |
15 |
Correct |
1 ms |
604 KB |
correct |
16 |
Correct |
1 ms |
604 KB |
correct |
17 |
Correct |
1 ms |
604 KB |
correct |
18 |
Correct |
1 ms |
604 KB |
correct |
19 |
Correct |
1 ms |
604 KB |
correct |
20 |
Correct |
1 ms |
604 KB |
correct |
21 |
Correct |
1 ms |
604 KB |
correct |
22 |
Correct |
1 ms |
452 KB |
correct |
23 |
Correct |
1 ms |
604 KB |
correct |
24 |
Correct |
1 ms |
448 KB |
correct |
25 |
Correct |
1 ms |
600 KB |
correct |
26 |
Correct |
1 ms |
604 KB |
correct |
27 |
Correct |
1 ms |
600 KB |
correct |
28 |
Correct |
1 ms |
604 KB |
correct |
29 |
Correct |
1 ms |
604 KB |
correct |
30 |
Correct |
1 ms |
604 KB |
correct |
31 |
Correct |
1 ms |
604 KB |
correct |
32 |
Correct |
1 ms |
456 KB |
correct |
33 |
Correct |
1 ms |
604 KB |
correct |
34 |
Correct |
20 ms |
2600 KB |
correct |
35 |
Correct |
19 ms |
2396 KB |
correct |
36 |
Correct |
17 ms |
2296 KB |
correct |
37 |
Correct |
6 ms |
1372 KB |
correct |
38 |
Correct |
19 ms |
2396 KB |
correct |
39 |
Correct |
18 ms |
2344 KB |
correct |
40 |
Correct |
18 ms |
2248 KB |
correct |
41 |
Correct |
20 ms |
2404 KB |
correct |
42 |
Correct |
25 ms |
2592 KB |
correct |
43 |
Correct |
12 ms |
2140 KB |
correct |
44 |
Correct |
11 ms |
1948 KB |
correct |
45 |
Correct |
11 ms |
1884 KB |
correct |
46 |
Correct |
10 ms |
1888 KB |
correct |
47 |
Correct |
7 ms |
1628 KB |
correct |
48 |
Correct |
3 ms |
1372 KB |
correct |
49 |
Correct |
5 ms |
1372 KB |
correct |
50 |
Correct |
7 ms |
1628 KB |
correct |
51 |
Correct |
12 ms |
1992 KB |
correct |
52 |
Correct |
16 ms |
1880 KB |
correct |
53 |
Correct |
10 ms |
1884 KB |
correct |
54 |
Correct |
15 ms |
2096 KB |
correct |
55 |
Correct |
11 ms |
1904 KB |
correct |
56 |
Correct |
11 ms |
1880 KB |
correct |
57 |
Correct |
10 ms |
2136 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
53 ms |
5204 KB |
correct |
4 |
Correct |
102 ms |
7484 KB |
correct |
5 |
Correct |
96 ms |
7248 KB |
correct |
6 |
Correct |
90 ms |
7484 KB |
correct |
7 |
Correct |
97 ms |
7484 KB |
correct |
8 |
Correct |
96 ms |
7256 KB |
correct |
9 |
Correct |
96 ms |
7472 KB |
correct |
10 |
Correct |
86 ms |
7516 KB |
correct |
11 |
Correct |
88 ms |
7496 KB |
correct |
12 |
Correct |
93 ms |
7484 KB |
correct |
13 |
Correct |
1 ms |
348 KB |
correct |
14 |
Correct |
113 ms |
7432 KB |
correct |
15 |
Correct |
86 ms |
7256 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
348 KB |
correct |
3 |
Correct |
1 ms |
704 KB |
correct |
4 |
Correct |
0 ms |
604 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
448 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
1 ms |
604 KB |
correct |
15 |
Correct |
1 ms |
604 KB |
correct |
16 |
Correct |
1 ms |
604 KB |
correct |
17 |
Correct |
1 ms |
604 KB |
correct |
18 |
Correct |
1 ms |
604 KB |
correct |
19 |
Correct |
1 ms |
604 KB |
correct |
20 |
Correct |
1 ms |
604 KB |
correct |
21 |
Correct |
1 ms |
604 KB |
correct |
22 |
Correct |
1 ms |
452 KB |
correct |
23 |
Correct |
1 ms |
604 KB |
correct |
24 |
Correct |
1 ms |
448 KB |
correct |
25 |
Correct |
1 ms |
600 KB |
correct |
26 |
Correct |
1 ms |
604 KB |
correct |
27 |
Correct |
1 ms |
600 KB |
correct |
28 |
Correct |
1 ms |
604 KB |
correct |
29 |
Correct |
1 ms |
604 KB |
correct |
30 |
Correct |
1 ms |
604 KB |
correct |
31 |
Correct |
1 ms |
604 KB |
correct |
32 |
Correct |
1 ms |
456 KB |
correct |
33 |
Correct |
1 ms |
604 KB |
correct |
34 |
Correct |
20 ms |
2600 KB |
correct |
35 |
Correct |
19 ms |
2396 KB |
correct |
36 |
Correct |
17 ms |
2296 KB |
correct |
37 |
Correct |
6 ms |
1372 KB |
correct |
38 |
Correct |
19 ms |
2396 KB |
correct |
39 |
Correct |
18 ms |
2344 KB |
correct |
40 |
Correct |
18 ms |
2248 KB |
correct |
41 |
Correct |
20 ms |
2404 KB |
correct |
42 |
Correct |
25 ms |
2592 KB |
correct |
43 |
Correct |
12 ms |
2140 KB |
correct |
44 |
Correct |
11 ms |
1948 KB |
correct |
45 |
Correct |
11 ms |
1884 KB |
correct |
46 |
Correct |
10 ms |
1888 KB |
correct |
47 |
Correct |
7 ms |
1628 KB |
correct |
48 |
Correct |
3 ms |
1372 KB |
correct |
49 |
Correct |
5 ms |
1372 KB |
correct |
50 |
Correct |
7 ms |
1628 KB |
correct |
51 |
Correct |
12 ms |
1992 KB |
correct |
52 |
Correct |
16 ms |
1880 KB |
correct |
53 |
Correct |
10 ms |
1884 KB |
correct |
54 |
Correct |
15 ms |
2096 KB |
correct |
55 |
Correct |
11 ms |
1904 KB |
correct |
56 |
Correct |
11 ms |
1880 KB |
correct |
57 |
Correct |
10 ms |
2136 KB |
correct |
58 |
Correct |
1 ms |
348 KB |
correct |
59 |
Correct |
0 ms |
348 KB |
correct |
60 |
Correct |
53 ms |
5204 KB |
correct |
61 |
Correct |
102 ms |
7484 KB |
correct |
62 |
Correct |
96 ms |
7248 KB |
correct |
63 |
Correct |
90 ms |
7484 KB |
correct |
64 |
Correct |
97 ms |
7484 KB |
correct |
65 |
Correct |
96 ms |
7256 KB |
correct |
66 |
Correct |
96 ms |
7472 KB |
correct |
67 |
Correct |
86 ms |
7516 KB |
correct |
68 |
Correct |
88 ms |
7496 KB |
correct |
69 |
Correct |
93 ms |
7484 KB |
correct |
70 |
Correct |
1 ms |
348 KB |
correct |
71 |
Correct |
113 ms |
7432 KB |
correct |
72 |
Correct |
86 ms |
7256 KB |
correct |
73 |
Correct |
0 ms |
348 KB |
correct |
74 |
Correct |
86 ms |
7260 KB |
correct |
75 |
Correct |
88 ms |
7260 KB |
correct |
76 |
Correct |
47 ms |
4208 KB |
correct |
77 |
Correct |
90 ms |
7512 KB |
correct |
78 |
Correct |
86 ms |
7484 KB |
correct |
79 |
Correct |
96 ms |
7432 KB |
correct |
80 |
Correct |
85 ms |
7260 KB |
correct |
81 |
Correct |
93 ms |
7000 KB |
correct |
82 |
Correct |
93 ms |
7400 KB |
correct |
83 |
Correct |
66 ms |
4952 KB |
correct |
84 |
Correct |
61 ms |
5664 KB |
correct |
85 |
Correct |
61 ms |
5600 KB |
correct |
86 |
Correct |
42 ms |
4156 KB |
correct |
87 |
Correct |
38 ms |
3928 KB |
correct |
88 |
Correct |
40 ms |
3504 KB |
correct |
89 |
Correct |
34 ms |
3420 KB |
correct |
90 |
Correct |
37 ms |
3160 KB |
correct |
91 |
Correct |
15 ms |
2392 KB |
correct |
92 |
Correct |
10 ms |
2396 KB |
correct |
93 |
Correct |
63 ms |
5420 KB |
correct |
94 |
Correct |
42 ms |
4188 KB |
correct |
95 |
Correct |
42 ms |
4364 KB |
correct |
96 |
Correct |
37 ms |
3160 KB |
correct |
97 |
Correct |
35 ms |
3568 KB |
correct |
98 |
Correct |
38 ms |
3944 KB |
correct |
99 |
Correct |
35 ms |
3532 KB |
correct |
100 |
Correct |
20 ms |
2648 KB |
correct |
101 |
Correct |
10 ms |
2396 KB |
correct |
102 |
Correct |
44 ms |
5028 KB |
correct |
103 |
Correct |
56 ms |
5028 KB |
correct |
104 |
Correct |
44 ms |
5008 KB |
correct |
105 |
Correct |
45 ms |
4972 KB |
correct |