# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
598237 |
2022-07-17T20:18:48 Z |
yanndev |
Simurgh (IOI17_simurgh) |
C++17 |
|
3000 ms |
7236 KB |
#include <bits/stdc++.h>
#include "simurgh.h"
#define fi first
#define se second
using namespace std;
const int IDK = 0;
const int NOT_ROYAL = 1;
const int ROYAL = 2;
vector<pair<int, int>> graph[542];
bool vis[542];
bool dfsTree[4242];
int status[4242];
int par[542];
vector<int> cur {};
int find(int node) {
return (par[node] < 0 ? node : par[node] = find(par[node]));
}
int sz(int node) {
return -par[find(node)];
}
bool unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return false;
if (sz(a) < sz(b))
swap(a, b);
par[a] += par[b];
par[b] = a;
return true;
}
void resetDsu(int n) {
for (int i = 0; i < n; i++)
par[i] = -1;
}
void dfs(int node) {
vis[node] = true;
for (auto& x: graph[node]) {
if (!vis[x.fi]) {
//printf("add edge %d\n", x.se);
dfsTree[x.se] = true;
cur.push_back(x.se);
dfs(x.fi);
}
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
int m = (int)u.size();
for (int i = 0; i < m; i++) {
graph[u[i]].push_back({v[i], i});
graph[v[i]].push_back({u[i], i});
}
memset(vis, false, sizeof(vis));
memset(dfsTree, false, sizeof(dfsTree));
dfs(0);
int orig = count_common_roads(cur);
while (orig != n - 1) {
bool done = false;
for (int idRem = 0; idRem < (int)cur.size(); idRem++) {
if (done)
break;
vector<int> newTree {};
for (auto& x: cur)
if (x != cur[idRem])
newTree.push_back(x);
for (int toAdd = 0; toAdd < m; toAdd++) {
if (!dfsTree[toAdd]) {
newTree.push_back(toAdd);
resetDsu(n);
bool ok = true;
for (auto& x: newTree) {
if (!unite(u[x], v[x]))
ok = false;
}
if (sz(0) != n)
ok = false;
if (ok) {
int newCnt = count_common_roads(newTree);
if (newCnt > orig) {
cur = newTree;
orig = newCnt;
done = true;
break;
}
}
newTree.pop_back();
}
}
}
}
/*printf("ans ");
for (auto& x: ans)
printf("%d ", x);
printf("\n");*/
return cur;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
312 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
312 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
14 ms |
340 KB |
correct |
15 |
Correct |
49 ms |
356 KB |
correct |
16 |
Correct |
58 ms |
460 KB |
correct |
17 |
Correct |
42 ms |
340 KB |
correct |
18 |
Correct |
33 ms |
324 KB |
correct |
19 |
Correct |
65 ms |
340 KB |
correct |
20 |
Correct |
33 ms |
340 KB |
correct |
21 |
Correct |
30 ms |
340 KB |
correct |
22 |
Correct |
128 ms |
340 KB |
correct |
23 |
Correct |
125 ms |
340 KB |
correct |
24 |
Correct |
93 ms |
340 KB |
correct |
25 |
Correct |
3 ms |
212 KB |
correct |
26 |
Correct |
90 ms |
340 KB |
correct |
27 |
Correct |
110 ms |
340 KB |
correct |
28 |
Correct |
38 ms |
212 KB |
correct |
29 |
Correct |
12 ms |
332 KB |
correct |
30 |
Correct |
78 ms |
340 KB |
correct |
31 |
Correct |
103 ms |
340 KB |
correct |
32 |
Correct |
94 ms |
340 KB |
correct |
33 |
Correct |
78 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
312 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
14 ms |
340 KB |
correct |
15 |
Correct |
49 ms |
356 KB |
correct |
16 |
Correct |
58 ms |
460 KB |
correct |
17 |
Correct |
42 ms |
340 KB |
correct |
18 |
Correct |
33 ms |
324 KB |
correct |
19 |
Correct |
65 ms |
340 KB |
correct |
20 |
Correct |
33 ms |
340 KB |
correct |
21 |
Correct |
30 ms |
340 KB |
correct |
22 |
Correct |
128 ms |
340 KB |
correct |
23 |
Correct |
125 ms |
340 KB |
correct |
24 |
Correct |
93 ms |
340 KB |
correct |
25 |
Correct |
3 ms |
212 KB |
correct |
26 |
Correct |
90 ms |
340 KB |
correct |
27 |
Correct |
110 ms |
340 KB |
correct |
28 |
Correct |
38 ms |
212 KB |
correct |
29 |
Correct |
12 ms |
332 KB |
correct |
30 |
Correct |
78 ms |
340 KB |
correct |
31 |
Correct |
103 ms |
340 KB |
correct |
32 |
Correct |
94 ms |
340 KB |
correct |
33 |
Correct |
78 ms |
340 KB |
correct |
34 |
Execution timed out |
3050 ms |
1492 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Runtime error |
18 ms |
7236 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
316 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
312 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
14 ms |
340 KB |
correct |
15 |
Correct |
49 ms |
356 KB |
correct |
16 |
Correct |
58 ms |
460 KB |
correct |
17 |
Correct |
42 ms |
340 KB |
correct |
18 |
Correct |
33 ms |
324 KB |
correct |
19 |
Correct |
65 ms |
340 KB |
correct |
20 |
Correct |
33 ms |
340 KB |
correct |
21 |
Correct |
30 ms |
340 KB |
correct |
22 |
Correct |
128 ms |
340 KB |
correct |
23 |
Correct |
125 ms |
340 KB |
correct |
24 |
Correct |
93 ms |
340 KB |
correct |
25 |
Correct |
3 ms |
212 KB |
correct |
26 |
Correct |
90 ms |
340 KB |
correct |
27 |
Correct |
110 ms |
340 KB |
correct |
28 |
Correct |
38 ms |
212 KB |
correct |
29 |
Correct |
12 ms |
332 KB |
correct |
30 |
Correct |
78 ms |
340 KB |
correct |
31 |
Correct |
103 ms |
340 KB |
correct |
32 |
Correct |
94 ms |
340 KB |
correct |
33 |
Correct |
78 ms |
340 KB |
correct |
34 |
Execution timed out |
3050 ms |
1492 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |