結果
問題 | No.1254 補強への架け橋 |
ユーザー |
|
提出日時 | 2020-10-09 22:39:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 281 ms / 2,000 ms |
コード長 | 3,374 bytes |
コンパイル時間 | 2,448 ms |
コンパイル使用メモリ | 197,292 KB |
実行使用メモリ | 34,944 KB |
最終ジャッジ日時 | 2024-07-20 13:04:33 |
合計ジャッジ時間 | 18,368 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 123 |
ソースコード
#include<bits/stdc++.h>using namespace std;#define rep(i,n) for(ll i=0;i<n;i++)#define repl(i,l,r) for(ll i=(l);i<(r);i++)#define per(i,n) for(ll i=n-1;i>=0;i--)#define perl(i,r,l) for(ll i=r-1;i>=l;i--)#define fi first#define se second#define pb push_back#define ins insert#define pqueue(x) priority_queue<x,vector<x>,greater<x>>#define all(x) (x).begin(),(x).end()#define CST(x) cout<<fixed<<setprecision(x)#define vtpl(x,y,z) vector<tuple<x,y,z>>#define rev(x) reverse(x);using ll=long long;using vl=vector<ll>;using vvl=vector<vector<ll>>;using pl=pair<ll,ll>;using vpl=vector<pl>;using vvpl=vector<vpl>;const ll MOD=1000000007;const ll MOD9=998244353;const int inf=1e9+10;const ll INF=4e18;const ll dy[9]={0,0,1,-1,1,1,-1,-1,0};const ll dx[9]={1,-1,0,0,1,-1,1,-1,0};template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}struct Edge {int to;};using Graph = vector<vector<Edge>>;using P = pair<long long, long long>;/* Lowlink: グラフの関節点・橋を列挙する構造体作成: O(E+V)関節点の集合: vector<int> aps橋の集合: vector<P> bridges*/struct LowLink {const Graph &G;vector<int> used, ord, low;vector<int> aps; // articulation pointsvector<P> bridges;LowLink(const Graph &G_) : G(G_) {used.assign(G.size(), 0);ord.assign(G.size(), 0);low.assign(G.size(), 0);int k = 0;for (int i = 0; i < (int)G.size(); i++) {if (!used[i]) k = dfs(i, k, -1);}sort(aps.begin(), aps.end()); // 必要ならソートするsort(bridges.begin(), bridges.end()); // 必要ならソートする}int dfs(int id, int k, int par) { // id:探索中の頂点, k:dfsで何番目に探索するか, par:idの親used[id] = true;ord[id] = k++;low[id] = ord[id];bool is_aps = false;int count = 0; // 子の数for (auto &e : G[id]) {if (!used[e.to]) {count++;k = dfs(e.to, k, id);low[id] = min(low[id], low[e.to]);if (par != -1 && ord[id] <= low[e.to]) is_aps = true;if (ord[id] < low[e.to]) bridges.emplace_back(min(id, e.to), max(id, e.to)); // 条件を満たすので橋} else if (e.to != par) { // eが後退辺の時low[id] = min(low[id], ord[e.to]);}}if (par == -1 && count >= 2) is_aps = true;if (is_aps) aps.push_back(id);return k;}};int main(){ll n;cin >> n;vector<pl> v(n);vector<vector<Edge>> g(n);map<pl,ll> mp;rep(i,n){cin >> v[i].fi >> v[i].se;if(v[i].fi>v[i].se)swap(v[i].fi,v[i].se);v[i].fi--;v[i].se--;mp[v[i]]=i+1;Edge a,b;a.to=v[i].fi;b.to=v[i].se;g[v[i].fi].pb(b);g[v[i].se].pb(a);}LowLink lk(g);set<ll> ans;rep(i,n)ans.ins(i+1);for(auto p:lk.bridges){ans.erase(mp[p]);//cout << p.fi << " " << p.se <<endl;}cout << ans.size() <<endl;for(auto p:ans)cout << p <<" ";cout << endl;}