# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030635 |
2024-07-22T08:02:00 Z |
vjudge1 |
Simurgh (IOI17_simurgh) |
C++17 |
|
1 ms |
348 KB |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rng(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
const int INF=INT_MAX>>1;
#include "simurgh.h"
struct UnionFind{
int size;
vector<int> uf;
UnionFind(int sz):size(sz){
uf.resize(sz,-1);
}
int leader(int x){
if(uf[x]<0)return x;
uf[x]=leader(uf[x]);
return uf[x];
}
bool same(int x,int y){
return leader(x)!=leader(y);
}
bool merge(int x,int y){
x=leader(x);
y=leader(y);
if(x==y)return false;
if(-uf[x]>-uf[y])swap(x,y);
uf[y]+=uf[x];
uf[x]=y;
return true;
}
};
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
vector<int> tree;
int m=u.size();
UnionFind uni(n);
rep(i,m){
if(uni.merge(u[i],v[i]))tree.emplace_back(i);
}
vector<int> ans;
int def=count_common_roads(tree);
vector<int> mark(m,0);
rep(i,n-1){
UnionFind uni(n);
int bef=tree[i];
rep(j,n-1){
if(i!=j)uni.merge(u[tree[j]],v[tree[j]]);
}
vector<pair<int,int>> num={{def,bef}};
bool checked=false;
rep(j,m){
if(j==bef)continue;
if(mark[j]!=0){
if(checked)continue;
checked=true;
}
if(!uni.same(u[j],v[j])){
tree[i]=j;
num.emplace_back(count_common_roads(tree),j);
tree[i]=bef;
}
}
sort(all(num));
for(auto &[v,j]:num){
if(v==num.back().first)mark[j]=1;
else mark[j]=-1;
}
}
rep(i,m){
if(mark[i]==1)ans.emplace_back(i);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
correct |
2 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |