# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
598159 |
2022-07-17T18:20:15 Z |
yanndev |
Simurgh (IOI17_simurgh) |
C++17 |
|
3000 ms |
7300 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 |
0 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
316 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
292 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
316 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
292 KB |
correct |
14 |
Correct |
16 ms |
368 KB |
correct |
15 |
Correct |
54 ms |
356 KB |
correct |
16 |
Correct |
63 ms |
364 KB |
correct |
17 |
Correct |
46 ms |
360 KB |
correct |
18 |
Correct |
34 ms |
340 KB |
correct |
19 |
Correct |
66 ms |
360 KB |
correct |
20 |
Correct |
37 ms |
360 KB |
correct |
21 |
Correct |
32 ms |
340 KB |
correct |
22 |
Correct |
138 ms |
340 KB |
correct |
23 |
Correct |
119 ms |
340 KB |
correct |
24 |
Correct |
94 ms |
340 KB |
correct |
25 |
Correct |
3 ms |
212 KB |
correct |
26 |
Correct |
94 ms |
340 KB |
correct |
27 |
Correct |
109 ms |
340 KB |
correct |
28 |
Correct |
38 ms |
212 KB |
correct |
29 |
Correct |
12 ms |
212 KB |
correct |
30 |
Correct |
82 ms |
344 KB |
correct |
31 |
Correct |
112 ms |
340 KB |
correct |
32 |
Correct |
95 ms |
332 KB |
correct |
33 |
Correct |
80 ms |
348 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
316 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
292 KB |
correct |
14 |
Correct |
16 ms |
368 KB |
correct |
15 |
Correct |
54 ms |
356 KB |
correct |
16 |
Correct |
63 ms |
364 KB |
correct |
17 |
Correct |
46 ms |
360 KB |
correct |
18 |
Correct |
34 ms |
340 KB |
correct |
19 |
Correct |
66 ms |
360 KB |
correct |
20 |
Correct |
37 ms |
360 KB |
correct |
21 |
Correct |
32 ms |
340 KB |
correct |
22 |
Correct |
138 ms |
340 KB |
correct |
23 |
Correct |
119 ms |
340 KB |
correct |
24 |
Correct |
94 ms |
340 KB |
correct |
25 |
Correct |
3 ms |
212 KB |
correct |
26 |
Correct |
94 ms |
340 KB |
correct |
27 |
Correct |
109 ms |
340 KB |
correct |
28 |
Correct |
38 ms |
212 KB |
correct |
29 |
Correct |
12 ms |
212 KB |
correct |
30 |
Correct |
82 ms |
344 KB |
correct |
31 |
Correct |
112 ms |
340 KB |
correct |
32 |
Correct |
95 ms |
332 KB |
correct |
33 |
Correct |
80 ms |
348 KB |
correct |
34 |
Execution timed out |
3090 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 |
21 ms |
7300 KB |
Execution killed with signal 11 |
4 |
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 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
316 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
292 KB |
correct |
14 |
Correct |
16 ms |
368 KB |
correct |
15 |
Correct |
54 ms |
356 KB |
correct |
16 |
Correct |
63 ms |
364 KB |
correct |
17 |
Correct |
46 ms |
360 KB |
correct |
18 |
Correct |
34 ms |
340 KB |
correct |
19 |
Correct |
66 ms |
360 KB |
correct |
20 |
Correct |
37 ms |
360 KB |
correct |
21 |
Correct |
32 ms |
340 KB |
correct |
22 |
Correct |
138 ms |
340 KB |
correct |
23 |
Correct |
119 ms |
340 KB |
correct |
24 |
Correct |
94 ms |
340 KB |
correct |
25 |
Correct |
3 ms |
212 KB |
correct |
26 |
Correct |
94 ms |
340 KB |
correct |
27 |
Correct |
109 ms |
340 KB |
correct |
28 |
Correct |
38 ms |
212 KB |
correct |
29 |
Correct |
12 ms |
212 KB |
correct |
30 |
Correct |
82 ms |
344 KB |
correct |
31 |
Correct |
112 ms |
340 KB |
correct |
32 |
Correct |
95 ms |
332 KB |
correct |
33 |
Correct |
80 ms |
348 KB |
correct |
34 |
Execution timed out |
3090 ms |
1492 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |