#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define maxn 505
struct unionfind{
int rnk[maxn],par[maxn];
void init(int n){
for(int i=0;i<n;++i)par[i]=i,rnk[i]=1;
}
int fp(int i){return (par[i]==i)?i:par[i]=fp(par[i]);}
void join(int x,int y){
x=fp(x),y=fp(y);
if(x==y)return;
if(rnk[x]<rnk[y])par[x]=y;
else par[y]=x;
if(rnk[x]==rnk[y])++rnk[x];
}
}ufds;
int num[maxn],low[maxn],par[maxn],cnt,bcnt,good[maxn*maxn];
bool in[maxn];
vector<pair<int,int>> AL[maxn];
vector<int> bcc[maxn];
stack<int> s;
void dfs(int u){
num[u]=low[u]=cnt++;
s.push(u);
for(auto[v,i]:AL[u]){
if(num[v]==-1){
par[v]=u;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=num[u]){
while(true){
int x=s.top();s.pop();
bcc[bcnt].push_back(x);
if(x==v)break;
}
bcc[bcnt].push_back(u);
++bcnt;
}
if(low[v]>num[u]){
good[i]=1;
}
}
else if(v!=par[u]){
low[u]=min(low[u],num[v]);
}
}
}
vector<int> find_roads(int n,vector<int> u,vector<int> v){
int m=u.size();
for(int i=0;i<m;++i){
AL[u[i]].push_back({v[i],i});
AL[v[i]].push_back({u[i],i});
}
memset(num,-1,sizeof num);
dfs(0);
for(int i=0;i<bcnt;++i){
if(bcc[i].size()==1)continue;
for(int x:bcc[i]){
in[x]=true;
}
for(int x:bcc[i]){
ufds.init(n);
vector<int> e,bcce;
for(int i=0;i<m;++i){
if((u[i]==x&&in[v[i]])||(v[i]==x&&in[u[i]])){
bcce.push_back(i);
continue;
}
if(ufds.fp(u[i])==ufds.fp(v[i]))continue;
e.push_back(i);
ufds.join(u[i],v[i]);
}
vector<pair<int,int>> res;
for(int i:bcce){
if(good[i]!=0)continue;
e.push_back(i);
res.push_back({count_common_roads(e),i});
e.pop_back();
}
sort(res.begin(),res.end());
int last=res.back().first;
for(int i=res.size()-1;i>=0;--i){
if(res[i].first==last)good[res[i].second]=1;
else good[res[i].second]=-1;
}
}
for(int x:bcc[i])in[x]=false;
}
vector<int> ans;
for(int i=0;i<m;++i){
if(good[i]==1)ans.push_back(i);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |