#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)5e2+2;
const int mxM = mxN*mxN/2;
int n, m, p[mxN], sz[mxN];
bool vis[mxM];
void init(int n){ for(int i = 0; i < n; i++) p[i]=i,sz[i]=1;}
int findSet(int i){return i==p[i]?i:p[i]=findSet(p[i]);}
bool isSameSet(int i, int j){return findSet(i)==findSet(j);}
void unionSet(int i, int j){
int x = findSet(i), y = findSet(j);
if(x==y) return;
if(sz[x]<sz[y]) swap(x,y);
p[y] = x; sz[x]+=sz[y];
}
vi find_roads(int N, vi u, vi v) {
vi ans; m = sz(u); n = N;
for(int i = 0; i < m; i++){
if(vis[i]) continue; init(n);
vector<int> V, w; V.clear(); w.clear();
for(int j = 0; j < m; j++){
if(isSameSet(u[j],v[j])) continue;
int x = findSet(u[i]), y = findSet(v[i]);
if(x>y) swap(x,y);
int x2 = findSet(u[j]), y2 = findSet(v[j]);
if(x2>y2) swap(x2,y2);
if(x==x2 and y==y2) V.pb(j);
else unionSet(u[j],v[j]), w.pb(j);
}
for(auto u : V) vis[u]=1;
pair<int,int> mx = {0,0};
for(int j = 0; j < sz(V); j++){
w.pb(V[j]); mx = max(mx, {count_common_roads(w),j}); w.pop_back();
}
ans.pb(mx.second);
}
return ans;
}
Compilation message
simurgh.cpp: In function 'vi find_roads(int, vi, vi)':
simurgh.cpp:24:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
24 | if(vis[i]) continue; init(n);
| ^~
simurgh.cpp:24:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
24 | if(vis[i]) continue; init(n);
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Incorrect |
1 ms |
212 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |