結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-10 17:46:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 314 ms / 2,000 ms |
| コード長 | 989 bytes |
| コンパイル時間 | 1,108 ms |
| コンパイル使用メモリ | 98,164 KB |
| 実行使用メモリ | 20,096 KB |
| 最終ジャッジ日時 | 2024-07-20 16:05:16 |
| 合計ジャッジ時間 | 18,861 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
using namespace std;
typedef pair<int,int> pii;
int main(){
int n;
cin >> n;
set<pii> s;
map<pii,int> m;
vector<int> deg(n+1, 0), v[n+1];
for(int i = 1; i <= n; i++){
int x, y;
cin >> x >> y;
deg[x]++, deg[y]++;
v[x].push_back(y);
v[y].push_back(x);
if(x > y) swap(x, y);
s.insert({x,y});
m[{x,y}] = i;
}
queue<int> leaf;
for(int i = 1; i <= n; i++) if(deg[i] == 1) leaf.push(i);
while(!leaf.empty()){
int l = leaf.front(); leaf.pop();
for(int next : v[l]){
deg[next]--;
s.erase({min(l,next), max(l,next)});
if(deg[next]==1) leaf.push(next);
}
}
cout << s.size() << endl;
bool f = true;
for(pii p : s){
if(f) f = false;
else cout << " ";
cout << m[p];
}
cout << endl;
return 0;
}