結果
問題 |
No.1254 補強への架け橋
|
ユーザー |
![]() |
提出日時 | 2020-10-17 14:23:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 450 ms / 2,000 ms |
コード長 | 999 bytes |
コンパイル時間 | 2,594 ms |
コンパイル使用メモリ | 205,924 KB |
最終ジャッジ日時 | 2025-01-15 10:48:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 123 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); i++) typedef long long ll; typedef long double ld; typedef pair<int,int> P; int main() { int n; cin >> n; vector<vector<int>> g(n); map<P, int> id; rep(i,n) { int a, b; cin >> a >> b; a--; b--; id[make_pair(a, b)] = i + 1; id[make_pair(b, a)] = i + 1; g[a].emplace_back(b); g[b].emplace_back(a); } vector<int> edge; vector<int> visited(n, 0); auto dfs = [&](auto& f, int p, int u)->int{ if (visited[u]) { visited[u] = -1; return 0; } visited[u] = 1; for (auto v : g[u]) { if (v == p) continue; int ok = f(f, u, v); if (ok == 0) { edge.emplace_back(id[make_pair(u, v)]); if (visited[u] == -1) return -1; return 0; } if (ok == -1) return -1; } return 1; }; dfs(dfs,-1,0); cout << edge.size() << endl; for (auto e : edge) cout << e << " "; cout << endl; return 0; }