結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-10-09 21:51:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 234 ms / 2,000 ms |
| コード長 | 2,097 bytes |
| コンパイル時間 | 1,660 ms |
| コンパイル使用メモリ | 142,440 KB |
| 最終ジャッジ日時 | 2025-01-15 04:27:23 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct TwoEdgeConnectedComponent{
int n, k;
vector<vector<int>> g, t;
vector<bool> used;
vector<int> comp, ord, low;
using edge=pair<int, int>;
vector<edge> br;
void dfs(int x, int prev, int &c){
used[x]=1;
ord[x]=c++;
low[x]=n;
bool mul=0;
for(auto y:g[x]){
if(used[y]){
if(y!=prev || mul) low[x]=min(low[x], ord[y]);
else mul=1;
continue;
}
dfs(y, x, c);
low[x]=min(low[x], low[y]);
}
}
void dfs2(int x, int num){
comp[x]=num;
for(auto y:g[x]){
if(comp[y]!=-1) continue;
if(ord[x]<low[y]){
br.push_back({x, y});
k++;
dfs2(y, k);
}else dfs2(y, num);
}
}
TwoEdgeConnectedComponent(const vector<vector<int>> &g):g(g), n(g.size()), used(n), comp(n, -1), ord(n), low(n), k(0){
int c=0;
for(int i=0; i<n; i++){
if(used[i]) continue;
dfs(i, -1, c);
dfs2(i, k);
k++;
}
}
void maketree(){
t.resize(k);
for(auto e:br){
int x=comp[e.first], y=comp[e.second];
t[x].push_back(y);
t[y].push_back(x);
}
}
};
int main()
{
int n; cin>>n;
vector<vector<int>> g(n);
int a[200020], b[200020];
for(int i=0; i<n; i++){
cin>>a[i]>>b[i];
a[i]--; b[i]--;
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
TwoEdgeConnectedComponent myon(g);
set<P> st;
for(auto p:myon.br){
st.insert(p);
st.insert({p.second, p.first});
}
vector<int> ans;
for(int i=0; i<n; i++){
if(st.find({a[i], b[i]})==st.end()) ans.push_back(i);
}
cout<<ans.size()<<endl;
for(auto x:ans) cout<<x+1<<" ";
cout<<endl;
return 0;
}
chocorusk