#include "simurgh.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
const int N = 505;
int f[N], t[N], CNT, P[N], h[N], Nn, up[N];
pii mn[N];
vector<int> golden;
vector<pii> V[N], adj[N];
vector<int> edges;
void dfs0(int u, int p) {
f[u] = 1;
for(int i = 0; i < V[u].size(); i++) {
if(V[u][i].f == p) continue;
if(!f[V[u][i].f]) {
dfs0(V[u][i].f, u);
edges.push_back(V[u][i].s);
t[V[u][i].s] = 1;
}
}
}
int rem(int e1, int e2) {
vector<int> x;
for(int i = 0; i < edges.size(); i++) {
if(e1 != edges[i]) x.push_back(edges[i]);
}
x.push_back(e2);
return count_common_roads(x) - CNT;
}
void add(int a, int b, int x) {
adj[a].push_back({b, x});
adj[b].push_back({a, -x});
}
void dfs(int u, int p) {
mn[u] = {Nn + 1, 0};
P[u] = p;
if(u) h[u] = h[p] + 1; //cout << u << endl;
for(int i = 0; i < V[u].size(); i++) {
int e = V[u][i].s, v = V[u][i].f;
if(v == p) continue;
if(t[e]) {
up[v] = e;
dfs(v, u);
if(mn[v].f > h[u]) golden[e] = 1;
else add(e, mn[v].s, rem(e, mn[v].s));
} else if(h[v] < h[u]) {
int x = u;
while(P[x] != v) {
x = P[x];
}
add(up[x], e, rem(up[x], e));
mn[u] = min(mn[u], {h[v], e});
}
}
}
std::vector<int> find_roads(int nn, std::vector<int> u, std::vector<int> vv) {
int m = u.size(); Nn = nn;
golden.resize(m);
for(int i = 0; i < m; i++) {
V[u[i]].push_back({vv[i], i});
V[vv[i]].push_back({u[i], i});
}
dfs0(0, -1); // 0dan iwyeba?
CNT = count_common_roads(edges);
dfs(0, -1);
vector<int> vis(m);
for(int i = 0; i < m; i++) {
if(!vis[i]) {
queue<int> q;
q.push(vis[i]);
h[i] = 0;
int mx = 0;
vector<int> x;
while(q.size()) {
int u = q.front(); q.pop();
for(int j = 0; j < adj[u].size(); j++) {
if(vis[adj[u][j].f]) continue;
h[adj[u][j].f] = h[u] + adj[u][j].s;
vis[adj[u][j].f] = 1;
q.push(adj[u][j].f);
}
x.push_back(u);
}
for(int j = 0; j < x.size(); j++) if(h[x[j]] == mx) golden[x[j]] = 1;
}
}
vector<int> ans;
for(int i = 0; i < m; i++) {
if(golden[i]) ans.push_back(i);
}
return ans;
}
Compilation message
simurgh.cpp: In function 'void dfs0(int, int)':
simurgh.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 0; i < V[u].size(); i++) {
| ~~^~~~~~~~~~~~~
simurgh.cpp: In function 'int rem(int, int)':
simurgh.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < edges.size(); i++) {
| ~~^~~~~~~~~~~~~~
simurgh.cpp: In function 'void dfs(int, int)':
simurgh.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < V[u].size(); i++) {
| ~~^~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:79:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int j = 0; j < adj[u].size(); j++) {
| ~~^~~~~~~~~~~~~~~
simurgh.cpp:87:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int j = 0; j < x.size(); j++) if(h[x[j]] == mx) golden[x[j]] = 1;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |