#include <bits/stdc++.h>
#define pb push_back
#include "simurgh.h"
using namespace std;
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
constexpr static int MXN = 500;
constexpr static int MXM = MXN * MXN;
bitset<MXN> visited;
bitset<MXM> bridge;
bitset<MXM> royal;
int bec[MXN]; // back edge count
int height[MXN];
int mheight[MXN];
int head[MXN];
vector<int> component[MXN];
vector<array<int, 2>> g[MXN];
void dfs(int node, int h, int edge_id)
{
visited[node] = true;
height[node] = h;
mheight[node] = h;
for (auto [c, ee] : g[node])
{
if (ee == edge_id)
continue;
if (visited[c])
{
if (node == 1)
debug(c, height[c]);
mheight[node] = min(mheight[node], height[c]);
continue;
}
dfs(c, h+1, ee);
mheight[node] = min(mheight[node], mheight[c]);
if (node == 1)
debug(node, mheight[c]);
}
debug(node, mheight[node], height[node], edge_id);
if (mheight[node] == height[node] && edge_id != -1)
bridge[edge_id] = true;
}
void dfs2(int node, int com)
{
visited[node] = true;
head[node] = com;
component[com].pb(node);
for (auto [c, ee] : g[node])
if (!visited[c] && !bridge[ee])
dfs2(c, com);
}
vector<int> r;
void find_st(int node, int ex)
{
visited[node] = true;
for (auto [c, ee] : g[node])
{
if (c == ex)
continue;
if (!visited[c])
{
r.pb(ee);
find_st(c, ex);
}
}
}
void process(int node)
{
// Creating rest of the tree
visited.reset();
r.clear();
bool first = true;
for (auto [c, ee] : g[node])
{
if (bridge[ee])
{
find_st(c, node);
r.pb(ee);
}
if (first && !bridge[ee])
find_st(c, node);
if (!bridge[ee])
first = false;
}
debug(node, r);
// Trying the edges one by one
int smaller = -1;
vector<int> counts(g[node].size(), -1);
bool ntp = false;
int smallest = MXN;
for (int i = 0; i < g[node].size(); i++)
{
auto [c, ee] = g[node][i];
if (bridge[ee])
continue;
if (c < node)
{
smaller = ee;
continue;
}
r.pb(ee);
counts[i] = count_common_roads(r);
smallest = min(smallest, counts[i]);
ntp = true;
r.pop_back();
}
if (!ntp)
return;
if (smaller != -1)
{
r.pb(smaller);
int rcount = count_common_roads(r);
r.pop_back();
if (!royal[smaller])
rcount++;
for (int i = 0; i < g[node].size(); i++)
{
auto [c, ee] = g[node][i];
if (counts[i] == -1)
continue;
royal[ee] = counts[i] == rcount;
}
}
else
{
bool has_bigger = false;
for (int i = 0; i < g[node].size(); i++)
if (counts[i] > smallest)
has_bigger = true;
if (!has_bigger)
{
for (int i = 0; i < g[node].size(); i++)
if (counts[i] != -1)
royal[g[node][i][1]] = true;
}
else
{
for (int i = 0; i < g[node].size(); i++)
if (counts[i] != -1)
royal[g[node][i][1]] = counts[i] != smallest;
}
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v)
{
int m = u.size();
for (int i = 0; i < m; i++)
{
g[u[i]].pb({v[i], i});
g[v[i]].pb({u[i], i});
}
dfs(0, 0, -1);
visited.reset();
int current = 1;
for (int i = 0; i < n; i++)
if (!head[i])
dfs2(i, current++);
for (int i = 0; i < m; i++)
royal[i] = bridge[i];
for (int i = 0; i < n; i++)
process(i);
debug(royal.count());
assert(royal.count() == n-1);
vector<int> res;
for (int i = 0; i < m; i++)
if (royal[i])
res.pb(i);
debug(res);
return res;
}
Compilation message
simurgh.cpp: In function 'void process(int)':
simurgh.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:128:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:139:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:144:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
144 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:150:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
150 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from simurgh.cpp:1:
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:179:23: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
179 | assert(royal.count() == n-1);
| ~~~~~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
2 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 ms |
340 KB |
correct |
20 |
Correct |
2 ms |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
464 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
2 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 ms |
340 KB |
correct |
20 |
Correct |
2 ms |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
464 KB |
correct |
34 |
Correct |
83 ms |
1520 KB |
correct |
35 |
Correct |
80 ms |
1492 KB |
correct |
36 |
Correct |
58 ms |
1364 KB |
correct |
37 |
Correct |
6 ms |
340 KB |
correct |
38 |
Correct |
85 ms |
1684 KB |
correct |
39 |
Correct |
70 ms |
1364 KB |
correct |
40 |
Correct |
72 ms |
1236 KB |
correct |
41 |
Correct |
83 ms |
1492 KB |
correct |
42 |
Correct |
81 ms |
1552 KB |
correct |
43 |
Correct |
46 ms |
1108 KB |
correct |
44 |
Correct |
37 ms |
888 KB |
correct |
45 |
Correct |
44 ms |
852 KB |
correct |
46 |
Correct |
34 ms |
852 KB |
correct |
47 |
Correct |
16 ms |
724 KB |
correct |
48 |
Correct |
2 ms |
340 KB |
correct |
49 |
Correct |
6 ms |
420 KB |
correct |
50 |
Correct |
16 ms |
596 KB |
correct |
51 |
Correct |
43 ms |
976 KB |
correct |
52 |
Correct |
37 ms |
852 KB |
correct |
53 |
Correct |
33 ms |
828 KB |
correct |
54 |
Correct |
47 ms |
1108 KB |
correct |
55 |
Correct |
44 ms |
852 KB |
correct |
56 |
Correct |
44 ms |
952 KB |
correct |
57 |
Correct |
44 ms |
960 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Incorrect |
66 ms |
3444 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
2 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 ms |
340 KB |
correct |
20 |
Correct |
2 ms |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
464 KB |
correct |
34 |
Correct |
83 ms |
1520 KB |
correct |
35 |
Correct |
80 ms |
1492 KB |
correct |
36 |
Correct |
58 ms |
1364 KB |
correct |
37 |
Correct |
6 ms |
340 KB |
correct |
38 |
Correct |
85 ms |
1684 KB |
correct |
39 |
Correct |
70 ms |
1364 KB |
correct |
40 |
Correct |
72 ms |
1236 KB |
correct |
41 |
Correct |
83 ms |
1492 KB |
correct |
42 |
Correct |
81 ms |
1552 KB |
correct |
43 |
Correct |
46 ms |
1108 KB |
correct |
44 |
Correct |
37 ms |
888 KB |
correct |
45 |
Correct |
44 ms |
852 KB |
correct |
46 |
Correct |
34 ms |
852 KB |
correct |
47 |
Correct |
16 ms |
724 KB |
correct |
48 |
Correct |
2 ms |
340 KB |
correct |
49 |
Correct |
6 ms |
420 KB |
correct |
50 |
Correct |
16 ms |
596 KB |
correct |
51 |
Correct |
43 ms |
976 KB |
correct |
52 |
Correct |
37 ms |
852 KB |
correct |
53 |
Correct |
33 ms |
828 KB |
correct |
54 |
Correct |
47 ms |
1108 KB |
correct |
55 |
Correct |
44 ms |
852 KB |
correct |
56 |
Correct |
44 ms |
952 KB |
correct |
57 |
Correct |
44 ms |
960 KB |
correct |
58 |
Correct |
1 ms |
212 KB |
correct |
59 |
Correct |
0 ms |
340 KB |
correct |
60 |
Incorrect |
66 ms |
3444 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |