結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
KowerKoint2010
|
| 提出日時 | 2025-08-06 14:09:07 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 262 ms / 2,000 ms |
| コード長 | 1,092 bytes |
| コンパイル時間 | 3,631 ms |
| コンパイル使用メモリ | 288,276 KB |
| 実行使用メモリ | 30,032 KB |
| 最終ジャッジ日時 | 2025-08-06 14:09:28 |
| 合計ジャッジ時間 | 15,882 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
#define PROBLEM "https://yukicoder.me/problems/no/1254"
#include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
using ll = long long;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
V<int> namori_loop(const V<V<int>>& g) {
V<int> roots;
V<int> seen(g.size());
int st;
auto dfs = [&](auto&& self, int u, int p) -> bool {
seen[u] = 1;
for(int v : g[u]) {
if(v == p) continue;
if(seen[v]) {
st = v;
roots.push_back(u);
return true;
}
if(self(self, v, u)) {
roots.push_back(u);
return u != st;
}
}
return false;
};
dfs(dfs, 0, -1);
return roots;
};
int main() {
int n; cin >> n;
V<V<int>> g(n);
map<pair<int, int>, int> eid;
REP(i, n) {
int a, b; cin >> a >> b; a--; b--;
g[a].push_back(b);
g[b].push_back(a);
eid[{a, b}] = eid[{b, a}] = i;
}
V<int> loop = namori_loop(g);
int m = loop.size();
cout << m << endl;
REP(i, m) {
cout << eid[{loop[i], loop[(i+1)%m]}]+1 << " \n"[i==m-1];
}
}
KowerKoint2010