#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
constexpr size_t N = 240;
vector<pair<int, int>> g[N];
int adj[N][N];
vector<int> find_roads(int n, vector<int> u, vector<int> v)
{
memset(adj, 255, sizeof adj);
for (int i = 0; i < u.size(); ++i)
g[u[i]].emplace_back(v[i], i), g[v[i]].emplace_back(u[i], i), adj[u[i]][v[i]] = adj[v[i]][u[i]] = i;
vector<int> ans;
for (int i = 0; i < n; ++i)
{
vector<vector<int>> bccs, bcc_trees;
vector<int> edge_to_bcc;
bitset<N> visited;
visited[i] = 1;
for (auto const &[z, j] : g[i])
if (!visited[z])
{
queue<int> q({z});
visited[z] = 1;
edge_to_bcc.push_back(j);
vector<int> nodes, edges;
while (!q.empty())
{
int x = q.front();
nodes.push_back(x);
q.pop();
for (auto const &[y, i] : g[x])
if (!visited[y])
{
edges.push_back(i);
q.push(y);
visited[y] = 1;
}
}
bccs.push_back(nodes);
bcc_trees.push_back(edges);
}
for (size_t j = 0; j < bccs.size(); ++j)
{
vector<int> spanning_tree;
for (size_t k = 0; k < bccs.size(); ++k)
{
spanning_tree.insert(spanning_tree.end(), bcc_trees[k].begin(), bcc_trees[k].end());
if (k != j)
spanning_tree.push_back(edge_to_bcc[k]);
}
for (auto const &x : bccs[j])
if (adj[i][x] != -1)
{
spanning_tree.push_back(adj[i][x]);
break;
}
int in_overlap = count_common_roads(spanning_tree), out_overlap = in_overlap;
vector<int> in;
bool skipped = 0;
for (auto const &x : bccs[j])
if (adj[i][x] != -1)
{
if (!skipped)
{
in.push_back(adj[i][x]);
skipped = 1;
continue;
}
spanning_tree.pop_back();
spanning_tree.push_back(adj[i][x]);
int y = count_common_roads(spanning_tree);
if (in_overlap == out_overlap)
{
if (y == in_overlap)
in.push_back(adj[i][x]);
else if (y < in_overlap)
{
out_overlap--;
}
else if (y > in_overlap)
{
in.clear();
in_overlap++;
in.push_back(adj[i][x]);
}
}
else if (y == in_overlap)
in.push_back(adj[i][x]);
}
ans.insert(ans.end(), in.begin(), in.end());
}
}
sort(ans.begin(), ans.end());
ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
return ans;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for (int i = 0; i < u.size(); ++i)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
correct |
2 |
Correct |
1 ms |
444 KB |
correct |
3 |
Correct |
1 ms |
468 KB |
correct |
4 |
Correct |
0 ms |
436 KB |
correct |
5 |
Correct |
1 ms |
468 KB |
correct |
6 |
Correct |
0 ms |
444 KB |
correct |
7 |
Correct |
1 ms |
468 KB |
correct |
8 |
Correct |
1 ms |
468 KB |
correct |
9 |
Correct |
1 ms |
468 KB |
correct |
10 |
Correct |
1 ms |
468 KB |
correct |
11 |
Correct |
1 ms |
468 KB |
correct |
12 |
Correct |
1 ms |
468 KB |
correct |
13 |
Correct |
0 ms |
468 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
correct |
2 |
Correct |
1 ms |
444 KB |
correct |
3 |
Correct |
1 ms |
468 KB |
correct |
4 |
Correct |
0 ms |
436 KB |
correct |
5 |
Correct |
1 ms |
468 KB |
correct |
6 |
Correct |
0 ms |
444 KB |
correct |
7 |
Correct |
1 ms |
468 KB |
correct |
8 |
Correct |
1 ms |
468 KB |
correct |
9 |
Correct |
1 ms |
468 KB |
correct |
10 |
Correct |
1 ms |
468 KB |
correct |
11 |
Correct |
1 ms |
468 KB |
correct |
12 |
Correct |
1 ms |
468 KB |
correct |
13 |
Correct |
0 ms |
468 KB |
correct |
14 |
Correct |
2 ms |
468 KB |
correct |
15 |
Correct |
2 ms |
468 KB |
correct |
16 |
Correct |
2 ms |
596 KB |
correct |
17 |
Correct |
2 ms |
596 KB |
correct |
18 |
Correct |
2 ms |
468 KB |
correct |
19 |
Correct |
2 ms |
468 KB |
correct |
20 |
Correct |
2 ms |
576 KB |
correct |
21 |
Correct |
2 ms |
468 KB |
correct |
22 |
Correct |
1 ms |
468 KB |
correct |
23 |
Correct |
1 ms |
468 KB |
correct |
24 |
Correct |
1 ms |
576 KB |
correct |
25 |
Correct |
1 ms |
468 KB |
correct |
26 |
Correct |
1 ms |
468 KB |
correct |
27 |
Correct |
1 ms |
468 KB |
correct |
28 |
Correct |
1 ms |
468 KB |
correct |
29 |
Correct |
1 ms |
468 KB |
correct |
30 |
Correct |
1 ms |
468 KB |
correct |
31 |
Correct |
1 ms |
468 KB |
correct |
32 |
Correct |
1 ms |
468 KB |
correct |
33 |
Correct |
2 ms |
468 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
correct |
2 |
Correct |
1 ms |
444 KB |
correct |
3 |
Correct |
1 ms |
468 KB |
correct |
4 |
Correct |
0 ms |
436 KB |
correct |
5 |
Correct |
1 ms |
468 KB |
correct |
6 |
Correct |
0 ms |
444 KB |
correct |
7 |
Correct |
1 ms |
468 KB |
correct |
8 |
Correct |
1 ms |
468 KB |
correct |
9 |
Correct |
1 ms |
468 KB |
correct |
10 |
Correct |
1 ms |
468 KB |
correct |
11 |
Correct |
1 ms |
468 KB |
correct |
12 |
Correct |
1 ms |
468 KB |
correct |
13 |
Correct |
0 ms |
468 KB |
correct |
14 |
Correct |
2 ms |
468 KB |
correct |
15 |
Correct |
2 ms |
468 KB |
correct |
16 |
Correct |
2 ms |
596 KB |
correct |
17 |
Correct |
2 ms |
596 KB |
correct |
18 |
Correct |
2 ms |
468 KB |
correct |
19 |
Correct |
2 ms |
468 KB |
correct |
20 |
Correct |
2 ms |
576 KB |
correct |
21 |
Correct |
2 ms |
468 KB |
correct |
22 |
Correct |
1 ms |
468 KB |
correct |
23 |
Correct |
1 ms |
468 KB |
correct |
24 |
Correct |
1 ms |
576 KB |
correct |
25 |
Correct |
1 ms |
468 KB |
correct |
26 |
Correct |
1 ms |
468 KB |
correct |
27 |
Correct |
1 ms |
468 KB |
correct |
28 |
Correct |
1 ms |
468 KB |
correct |
29 |
Correct |
1 ms |
468 KB |
correct |
30 |
Correct |
1 ms |
468 KB |
correct |
31 |
Correct |
1 ms |
468 KB |
correct |
32 |
Correct |
1 ms |
468 KB |
correct |
33 |
Correct |
2 ms |
468 KB |
correct |
34 |
Incorrect |
80 ms |
1748 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
correct |
2 |
Correct |
1 ms |
468 KB |
correct |
3 |
Runtime error |
14 ms |
4000 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
correct |
2 |
Correct |
1 ms |
444 KB |
correct |
3 |
Correct |
1 ms |
468 KB |
correct |
4 |
Correct |
0 ms |
436 KB |
correct |
5 |
Correct |
1 ms |
468 KB |
correct |
6 |
Correct |
0 ms |
444 KB |
correct |
7 |
Correct |
1 ms |
468 KB |
correct |
8 |
Correct |
1 ms |
468 KB |
correct |
9 |
Correct |
1 ms |
468 KB |
correct |
10 |
Correct |
1 ms |
468 KB |
correct |
11 |
Correct |
1 ms |
468 KB |
correct |
12 |
Correct |
1 ms |
468 KB |
correct |
13 |
Correct |
0 ms |
468 KB |
correct |
14 |
Correct |
2 ms |
468 KB |
correct |
15 |
Correct |
2 ms |
468 KB |
correct |
16 |
Correct |
2 ms |
596 KB |
correct |
17 |
Correct |
2 ms |
596 KB |
correct |
18 |
Correct |
2 ms |
468 KB |
correct |
19 |
Correct |
2 ms |
468 KB |
correct |
20 |
Correct |
2 ms |
576 KB |
correct |
21 |
Correct |
2 ms |
468 KB |
correct |
22 |
Correct |
1 ms |
468 KB |
correct |
23 |
Correct |
1 ms |
468 KB |
correct |
24 |
Correct |
1 ms |
576 KB |
correct |
25 |
Correct |
1 ms |
468 KB |
correct |
26 |
Correct |
1 ms |
468 KB |
correct |
27 |
Correct |
1 ms |
468 KB |
correct |
28 |
Correct |
1 ms |
468 KB |
correct |
29 |
Correct |
1 ms |
468 KB |
correct |
30 |
Correct |
1 ms |
468 KB |
correct |
31 |
Correct |
1 ms |
468 KB |
correct |
32 |
Correct |
1 ms |
468 KB |
correct |
33 |
Correct |
2 ms |
468 KB |
correct |
34 |
Incorrect |
80 ms |
1748 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |