結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2020-10-09 22:53:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 2,000 ms |
| コード長 | 2,182 bytes |
| コンパイル時間 | 1,862 ms |
| コンパイル使用メモリ | 102,804 KB |
| 実行使用メモリ | 35,360 KB |
| 最終ジャッジ日時 | 2024-07-20 13:28:45 |
| 合計ジャッジ時間 | 10,979 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
struct Edge{
int from,to;
ll cost;
int id;
Edge(){}
Edge(int from,int to,ll cost=1,int id=0):from(from),to(to),cost(cost),id(id){}
};
struct LowLink{
int N;
vector<vector<Edge>> g;
vector<int> ord,low,vis;
vector<int> articulations;
vector<Edge> bridges;
LowLink(int N,vector<vector<Edge>> &g):N(N),g(g),ord(N),low(N),vis(N){}
void dfs(int now,int par,int &cnt){
ord[now]=cnt++;
vis[now]=1;
bool isArt=false;
int num=0;
low[now]=ord[now];
for(auto e:g[now]){
if(e.to==par) continue;
if(vis[e.to]){
chmin(low[now],ord[e.to]);
}else{
num++;
dfs(e.to,now,cnt);
chmin(low[now],low[e.to]);
if(ord[now]<low[e.to]) bridges.emplace_back(e);
if(ord[now]<=low[e.to]) isArt=true;
}
}
if(par==-1&&num>1) articulations.push_back(now);
if(par!=-1&&isArt) articulations.push_back(now);
}
void build(){
int cnt=0;
for(int i=0;i<N;i++) if(vis[i]==0) dfs(i,-1,cnt);
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
vector<vector<Edge>> g(N);
rep(i,N){
int a,b;
cin>>a>>b;
a--;b--;
g[a].emplace_back(Edge{a,b,1,i});
g[b].emplace_back(Edge{b,a,1,i});
}
LowLink LL(N,g);
LL.build();
vector<Edge> bridges=LL.bridges;
vector<int> used(N,0);
for(auto e:bridges) used[e.id]=1;
vector<int> ans;
rep(i,N) if(used[i]==0) ans.push_back(i);
cout<<ans.size()<<endl;
rep(i,ans.size()) cout<<ans[i]+1<<" ";
cout<<endl;
return 0;
}
snow39