結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-10-09 22:22:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,380 bytes |
| コンパイル時間 | 2,695 ms |
| コンパイル使用メモリ | 204,496 KB |
| 最終ジャッジ日時 | 2025-01-15 05:05:45 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 121 MLE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;
vector<int> dfs(int v, int p, vector<bool> &visited, const graph &to, vector<int> route) {
visited.at(v) = true;
for (int next : to.at(v)) {
if (next == p) continue;
route.push_back(v);
if (visited.at(next)) {
route.push_back(next);
return route;
}
auto res = dfs(next, v, visited, to, route);
if (not res.empty()) return res;
route.pop_back();
}
return {};
}
int main() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i) >> b.at(i);
a.at(i)--;
b.at(i)--;
}
graph to(n);
for (int i = 0; i < n; i++) {
to.at(a.at(i)).push_back(b.at(i));
to.at(b.at(i)).push_back(a.at(i));
}
vector<int> route;
vector<bool> visited(n);
auto res = dfs(0, -1, visited, to, route);
int s = res.back();
res.pop_back();
reverse(res.begin(), res.end());
vector<bool> inloop(n);
for (int v : res) {
inloop.at(v) = true;
if (v == s) break;
}
cout << count(inloop.begin(), inloop.end(), true) << endl;
for (int i = 0; i < n; i++) {
if (inloop.at(a.at(i)) and inloop.at(b.at(i))) {
cout << i + 1 << " ";
}
}
cout << endl;
}
trineutron