# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
758690 | 2023-06-15T06:20:38 Z | boris_mihov | Simurgh (IOI17_simurgh) | C++17 | 82 ms | 6740 KB |
#include "simurgh.h" #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> #include <set> typedef long long llong; const int MAXN = 500 + 10; const int MAXM = 30000; const int INF = 1e9; int n, m; int timer; int inComp[MAXN]; std::set <int> s; std::vector <int> ans; std::vector <int> spanning; std::vector <std::pair <int,int>> edges; std::vector <std::pair <int,int>> g[MAXN]; bool isGood[MAXM]; void dfs(int node) { inComp[node] = timer; for (const auto &[i, idx] : g[node]) { if (inComp[i] == 0) { spanning.push_back(idx); dfs(i); } } } std::vector <int> find_roads(int N, std::vector <int> u, std::vector <int> v) { n = N; m = u.size(); for (int i = 0 ; i < m ; ++i) { g[u[i] + 1].push_back({v[i] + 1, i}); g[v[i] + 1].push_back({u[i] + 1, i}); } int last = -1; int res = -1; for (int i = 1 ; i <= n ; ++i) { timer = 0; spanning.clear(); std::fill(inComp + 1, inComp + 1 + n, 0); bool didntPush = true; inComp[i] = -1; for (const int &j : ans) { isGood[j] = true; } for (int j = 1 ; j <= n ; ++j) { if (inComp[j] != 0) { continue; } timer++; dfs(j); } std::sort(g[i].begin(), g[i].end(), [&](auto x, auto y) { return inComp[x.first] < inComp[y.first]; }); int curr = spanning.size(); for (int j = 0 ; j < g[i].size() ; ++j) { if (j == 0 || inComp[g[i][j - 1].first] < inComp[g[i][j].first]) { spanning.push_back(g[i][j].second); } } for (int j = 0 ; j <= g[i].size() ; ++j) { if (j == g[i].size() || (j > 0 && inComp[g[i][j - 1].first] < inComp[g[i][j].first])) { assert (edges.size()); std::sort(edges.begin(), edges.end(), [&](auto x, auto y) { return x.second < y.second; }); ans.push_back(edges.back().first); // std::cout << "in for: " << edges.back().first << ' ' << edges.back().second << '\n'; for (int k = (int)edges.size() - 2 ; k >= 0 ; --k) { if (edges[k].second != edges[k + 1].second) { // std::cout << "break: " << edges[k].second << ' ' << edges[k + 1].second << '\n'; break; } // std::cout << "in for: " << edges[k].first << ' ' << edges[k].second << ' ' << edges[k + 1].second << '\n'; ans.push_back(edges[k].first); } curr++; edges.clear(); didntPush = true; if (j == g[i].size()) { break; } } if (i < g[i][j].first) { spanning[curr] = g[i][j].second; res = count_common_roads(spanning); // std::cout << "push: " << edges.size() << ' ' << g[i][j].second << ' ' << res << '\n'; edges.push_back({g[i][j].second, res}); } else if (didntPush && isGood[g[i][j].second]) { didntPush = false; spanning[curr] = g[i][j].second; res = count_common_roads(spanning); // std::cout << "push: " << edges.size() << ' ' << g[i][j].second << ' ' << res << '\n'; edges.push_back({g[i][j].second, res}); } } } for (const int &i : ans) { s.insert(i); } ans.clear(); for (const int &i : s) { ans.push_back(i); } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | correct |
2 | Correct | 0 ms | 212 KB | correct |
3 | Correct | 1 ms | 212 KB | correct |
4 | Correct | 0 ms | 212 KB | correct |
5 | Correct | 0 ms | 212 KB | correct |
6 | Correct | 0 ms | 212 KB | correct |
7 | Correct | 0 ms | 212 KB | correct |
8 | Correct | 0 ms | 212 KB | correct |
9 | Correct | 0 ms | 212 KB | correct |
10 | Correct | 0 ms | 212 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 | 0 ms | 212 KB | correct |
3 | Correct | 1 ms | 212 KB | correct |
4 | Correct | 0 ms | 212 KB | correct |
5 | Correct | 0 ms | 212 KB | correct |
6 | Correct | 0 ms | 212 KB | correct |
7 | Correct | 0 ms | 212 KB | correct |
8 | Correct | 0 ms | 212 KB | correct |
9 | Correct | 0 ms | 212 KB | correct |
10 | Correct | 0 ms | 212 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 | 2 ms | 340 KB | correct |
15 | Correct | 2 ms | 340 KB | correct |
16 | Correct | 1 ms | 340 KB | correct |
17 | Correct | 1 ms | 340 KB | correct |
18 | Correct | 1 ms | 340 KB | correct |
19 | Correct | 1 ms | 340 KB | correct |
20 | Correct | 1 ms | 340 KB | correct |
21 | Correct | 1 ms | 340 KB | correct |
22 | Correct | 2 ms | 340 KB | correct |
23 | Correct | 2 ms | 340 KB | correct |
24 | Correct | 1 ms | 340 KB | correct |
25 | Correct | 1 ms | 212 KB | correct |
26 | Correct | 1 ms | 340 KB | correct |
27 | Correct | 1 ms | 340 KB | correct |
28 | Correct | 1 ms | 212 KB | correct |
29 | Correct | 1 ms | 212 KB | correct |
30 | Correct | 1 ms | 348 KB | correct |
31 | Correct | 1 ms | 340 KB | correct |
32 | Correct | 1 ms | 340 KB | correct |
33 | Correct | 1 ms | 340 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | correct |
2 | Correct | 0 ms | 212 KB | correct |
3 | Correct | 1 ms | 212 KB | correct |
4 | Correct | 0 ms | 212 KB | correct |
5 | Correct | 0 ms | 212 KB | correct |
6 | Correct | 0 ms | 212 KB | correct |
7 | Correct | 0 ms | 212 KB | correct |
8 | Correct | 0 ms | 212 KB | correct |
9 | Correct | 0 ms | 212 KB | correct |
10 | Correct | 0 ms | 212 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 | 2 ms | 340 KB | correct |
15 | Correct | 2 ms | 340 KB | correct |
16 | Correct | 1 ms | 340 KB | correct |
17 | Correct | 1 ms | 340 KB | correct |
18 | Correct | 1 ms | 340 KB | correct |
19 | Correct | 1 ms | 340 KB | correct |
20 | Correct | 1 ms | 340 KB | correct |
21 | Correct | 1 ms | 340 KB | correct |
22 | Correct | 2 ms | 340 KB | correct |
23 | Correct | 2 ms | 340 KB | correct |
24 | Correct | 1 ms | 340 KB | correct |
25 | Correct | 1 ms | 212 KB | correct |
26 | Correct | 1 ms | 340 KB | correct |
27 | Correct | 1 ms | 340 KB | correct |
28 | Correct | 1 ms | 212 KB | correct |
29 | Correct | 1 ms | 212 KB | correct |
30 | Correct | 1 ms | 348 KB | correct |
31 | Correct | 1 ms | 340 KB | correct |
32 | Correct | 1 ms | 340 KB | correct |
33 | Correct | 1 ms | 340 KB | correct |
34 | Correct | 74 ms | 1364 KB | correct |
35 | Correct | 72 ms | 1528 KB | correct |
36 | Correct | 51 ms | 1236 KB | correct |
37 | Correct | 5 ms | 340 KB | correct |
38 | Correct | 80 ms | 1608 KB | correct |
39 | Correct | 64 ms | 1484 KB | correct |
40 | Correct | 53 ms | 1340 KB | correct |
41 | Correct | 82 ms | 1556 KB | correct |
42 | Correct | 73 ms | 1544 KB | correct |
43 | Correct | 42 ms | 1148 KB | correct |
44 | Correct | 34 ms | 852 KB | correct |
45 | Correct | 39 ms | 844 KB | correct |
46 | Correct | 30 ms | 724 KB | correct |
47 | Correct | 14 ms | 584 KB | correct |
48 | Correct | 3 ms | 340 KB | correct |
49 | Correct | 5 ms | 324 KB | correct |
50 | Correct | 14 ms | 468 KB | correct |
51 | Correct | 38 ms | 940 KB | correct |
52 | Correct | 33 ms | 752 KB | correct |
53 | Correct | 30 ms | 828 KB | correct |
54 | Correct | 41 ms | 1144 KB | correct |
55 | Correct | 39 ms | 932 KB | correct |
56 | Correct | 48 ms | 948 KB | correct |
57 | Correct | 39 ms | 852 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | correct |
2 | Correct | 1 ms | 212 KB | correct |
3 | Runtime error | 20 ms | 6740 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 | 0 ms | 212 KB | correct |
3 | Correct | 1 ms | 212 KB | correct |
4 | Correct | 0 ms | 212 KB | correct |
5 | Correct | 0 ms | 212 KB | correct |
6 | Correct | 0 ms | 212 KB | correct |
7 | Correct | 0 ms | 212 KB | correct |
8 | Correct | 0 ms | 212 KB | correct |
9 | Correct | 0 ms | 212 KB | correct |
10 | Correct | 0 ms | 212 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 | 2 ms | 340 KB | correct |
15 | Correct | 2 ms | 340 KB | correct |
16 | Correct | 1 ms | 340 KB | correct |
17 | Correct | 1 ms | 340 KB | correct |
18 | Correct | 1 ms | 340 KB | correct |
19 | Correct | 1 ms | 340 KB | correct |
20 | Correct | 1 ms | 340 KB | correct |
21 | Correct | 1 ms | 340 KB | correct |
22 | Correct | 2 ms | 340 KB | correct |
23 | Correct | 2 ms | 340 KB | correct |
24 | Correct | 1 ms | 340 KB | correct |
25 | Correct | 1 ms | 212 KB | correct |
26 | Correct | 1 ms | 340 KB | correct |
27 | Correct | 1 ms | 340 KB | correct |
28 | Correct | 1 ms | 212 KB | correct |
29 | Correct | 1 ms | 212 KB | correct |
30 | Correct | 1 ms | 348 KB | correct |
31 | Correct | 1 ms | 340 KB | correct |
32 | Correct | 1 ms | 340 KB | correct |
33 | Correct | 1 ms | 340 KB | correct |
34 | Correct | 74 ms | 1364 KB | correct |
35 | Correct | 72 ms | 1528 KB | correct |
36 | Correct | 51 ms | 1236 KB | correct |
37 | Correct | 5 ms | 340 KB | correct |
38 | Correct | 80 ms | 1608 KB | correct |
39 | Correct | 64 ms | 1484 KB | correct |
40 | Correct | 53 ms | 1340 KB | correct |
41 | Correct | 82 ms | 1556 KB | correct |
42 | Correct | 73 ms | 1544 KB | correct |
43 | Correct | 42 ms | 1148 KB | correct |
44 | Correct | 34 ms | 852 KB | correct |
45 | Correct | 39 ms | 844 KB | correct |
46 | Correct | 30 ms | 724 KB | correct |
47 | Correct | 14 ms | 584 KB | correct |
48 | Correct | 3 ms | 340 KB | correct |
49 | Correct | 5 ms | 324 KB | correct |
50 | Correct | 14 ms | 468 KB | correct |
51 | Correct | 38 ms | 940 KB | correct |
52 | Correct | 33 ms | 752 KB | correct |
53 | Correct | 30 ms | 828 KB | correct |
54 | Correct | 41 ms | 1144 KB | correct |
55 | Correct | 39 ms | 932 KB | correct |
56 | Correct | 48 ms | 948 KB | correct |
57 | Correct | 39 ms | 852 KB | correct |
58 | Correct | 0 ms | 212 KB | correct |
59 | Correct | 1 ms | 212 KB | correct |
60 | Runtime error | 20 ms | 6740 KB | Execution killed with signal 11 |
61 | Halted | 0 ms | 0 KB | - |