#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=250000;
vector<pii> adj[M];
bool vis[M];
vii sp;
void dfs(ll x) {
vis[x]=1;
for(auto it:adj[x]) {
if(vis[it.F])
continue;
else {
sp.pb(it.S);
dfs(it.F);
}
}
}
struct dsu {
ll sz[250],pa[250];
void init(ll x) {
for(int i=0;i<x;i++)
sz[i]=1,pa[i]=i;
}
ll get(ll x) {
if(x==pa[x])
return x;
return pa[x]=get(pa[x]);
}
void unite(ll x,ll y) {
x=get(x),y=get(y);
if(x==y)
return;
if(sz[x]>sz[y])
swap(x,y);
pa[x]=y;
sz[y]+=sz[x];
}
bool same(ll x,ll y) {
return get(x)==get(y);
}
}d;
ll cnt[M],cc[M];
set<ll>s;
vector<int> find_roads(int n, std::vector<int> u, std::vector<int> vv) {
for(int i=0;i<u.size();i++)
adj[u[i]].pb({vv[i],i}),adj[vv[i]].pb({u[i],i});
dfs(0);
vector<int>ans,res;
for(int i=0;i<u.size();i++)
vis[i]=0;
ll cc=0;
for(auto it:sp) {
s.clear();
ans.clear();
d.init(n);
vii v;
for(auto itt:sp) {
if(itt!=it)
ans.pb(itt),d.unite(u[itt],vv[itt]);
}
for(int i=0;i<u.size();i++)
cnt[i]=0;
for(int i=0;i<u.size();i++) {
if(!vis[i]&&!d.same(u[i],vv[i])) {
ans.pb(i);
ll x=count_common_roads(ans);
cc++;
cnt[ans.back()]=x;
s.insert(x);
v.pb(i);
vis[i]=1;
ans.pop_back();
}
}
if(s.size()==1) {
bool chk=1;
for(auto itt:res) {
if(!d.same(u[itt],vv[itt]))
chk=0;
}
if(chk) {
for(auto it:v)
res.pb(it);
}
}
else {
for(auto it:v) {
if(cnt[it]!=*s.begin()) {
res.pb(it);
}
}
}
}
//assert(res.size()==n-1);
//assert(cc<=30000);
return res;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
simurgh.cpp:57:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
simurgh.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
simurgh.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=0;i<u.size();i++) {
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
correct |
2 |
Correct |
3 ms |
6236 KB |
correct |
3 |
Correct |
2 ms |
6316 KB |
correct |
4 |
Incorrect |
2 ms |
6236 KB |
WA in grader: NO |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
correct |
2 |
Correct |
3 ms |
6236 KB |
correct |
3 |
Correct |
2 ms |
6316 KB |
correct |
4 |
Incorrect |
2 ms |
6236 KB |
WA in grader: NO |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
correct |
2 |
Correct |
3 ms |
6236 KB |
correct |
3 |
Correct |
2 ms |
6316 KB |
correct |
4 |
Incorrect |
2 ms |
6236 KB |
WA in grader: NO |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
correct |
2 |
Correct |
3 ms |
6232 KB |
correct |
3 |
Runtime error |
21 ms |
22620 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6236 KB |
correct |
2 |
Correct |
3 ms |
6236 KB |
correct |
3 |
Correct |
2 ms |
6316 KB |
correct |
4 |
Incorrect |
2 ms |
6236 KB |
WA in grader: NO |
5 |
Halted |
0 ms |
0 KB |
- |