結果
問題 | No.1254 補強への架け橋 |
ユーザー |
![]() |
提出日時 | 2020-10-16 00:20:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 1,292 bytes |
コンパイル時間 | 1,970 ms |
コンパイル使用メモリ | 178,132 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-20 20:10:10 |
合計ジャッジ時間 | 14,314 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 123 |
ソースコード
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; typedef pair<ll, ll> P; const ll INF = (1LL<<48); struct edge{ int to, id; edge(){} edge(int a, int b) : to(a), id(b){} }; using ve = vector<edge>; int main() { cin>>N; vector<ve> G(N, ve(0)); vec num(N, 0); rep(i, N){ int a, b; cin>>a>>b; --a, --b; G[a].emplace_back(b, i); G[b].emplace_back(a, i); ++num[a]; ++num[b]; } vec ans(N, 1); queue<int> que; rep(i, N) if(num[i] == 1) que.push(i); while(!que.empty()){ int v = que.front(); que.pop(); for(edge &e : G[v]){ if(ans[e.id]){ ans[e.id] = 0; --num[e.to]; if(num[e.to] == 1) que.push(e.to); } } } int sum = accumulate(ALL(ans), 0LL); cout<<sum<<endl; rep(i, N) if(ans[i]) cout<<i + 1 <<(--sum ? ' ' : '\n'); }