#include <bits/stdc++.h>
#define pb push_back
#include "simurgh.h"
using namespace std;
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 (visited[c])
{
mheight[node] = min(mheight[node], height[c]);
continue;
}
dfs(c, h+1, ee);
mheight[node] = min(mheight[node], mheight[c]);
}
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] || first)
find_st(c, node);
if (!bridge[ee])
first = false;
}
// 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);
assert(royal.count() == n-1);
vector<int> res;
for (int i = 0; i < m; i++)
if (royal[i])
res.pb(i);
return res;
}
Compilation message
simurgh.cpp: In function 'void process(int)':
simurgh.cpp:83: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]
83 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:108: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]
108 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:119: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]
119 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:124: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]
124 | for (int i = 0; i < g[node].size(); i++)
| ~~^~~~~~~~~~~~~~~~
simurgh.cpp:130: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]
130 | 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:158:23: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
158 | assert(royal.count() == n-1);
| ~~~~~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
324 KB |
correct |
4 |
Correct |
0 ms |
324 KB |
correct |
5 |
Correct |
1 ms |
340 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
328 KB |
correct |
8 |
Correct |
1 ms |
340 KB |
correct |
9 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
324 KB |
correct |
4 |
Correct |
0 ms |
324 KB |
correct |
5 |
Correct |
1 ms |
340 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
328 KB |
correct |
8 |
Correct |
1 ms |
340 KB |
correct |
9 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
324 KB |
correct |
4 |
Correct |
0 ms |
324 KB |
correct |
5 |
Correct |
1 ms |
340 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
328 KB |
correct |
8 |
Correct |
1 ms |
340 KB |
correct |
9 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Incorrect |
71 ms |
4036 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
324 KB |
correct |
4 |
Correct |
0 ms |
324 KB |
correct |
5 |
Correct |
1 ms |
340 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
328 KB |
correct |
8 |
Correct |
1 ms |
340 KB |
correct |
9 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
10 |
Halted |
0 ms |
0 KB |
- |