結果
| 問題 | No.408 五輪ピック |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-18 18:15:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,230 bytes |
| 記録 | |
| コンパイル時間 | 1,033 ms |
| コンパイル使用メモリ | 85,988 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-22 12:34:05 |
| 合計ジャッジ時間 | 2,822 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
int main() {
// input
int n, m; cin >> n >> m;
vector<int> a(m), b(m);
repeat (i,m) {
cin >> a[i] >> b[i]; -- a[i]; -- b[i];
}
// make graph
const int root = 0;
vector<vector<int> > g(n);
repeat (i,m) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
// select vertices
set<int> d1; for (int i : g[root]) d1.insert(i);
vector<set<int> > g1(n); repeat (i,n) for (int j : g[i]) if (d1.count(j)) g1[i].insert(j);
// find cycle
bool ans = false;
repeat (e,m) {
int i = a[e];
int j = b[e];
bool g1_i_count_j = g1[i].count(j); g1[i].erase(j);
bool g1_j_count_i = g1[j].count(i); g1[j].erase(i);
if (not g1[i].empty() and not g1[j].empty()) {
if (not (g1[i].size() == 1 and g1[j].size() == 1 and g1[i] == g1[j])) {
ans = true;
}
}
if (g1_i_count_j) g1[i].insert(j);
if (g1_j_count_i) g1[j].insert(i);
if (ans) goto done;
}
done:
// output
cout << (ans ? "YES" : "NO") << endl;
return 0;
}