結果
| 問題 | No.408 五輪ピック |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-18 18:11:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,152 bytes |
| 記録 | |
| コンパイル時間 | 825 ms |
| コンパイル使用メモリ | 84,968 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-11-22 12:33:24 |
| 合計ジャッジ時間 | 2,549 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 11 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
int main() {
int n, m; cin >> n >> m;
vector<vector<int> > g(n);
repeat (i,m) {
int a, b; cin >> a >> b; -- a; -- b;
g[a].push_back(b);
g[b].push_back(a);
}
const int root = 0;
set<int> d1; for (int i : g[root]) d1.insert(i);
set<int> d2; for (int i : g[root]) for (int j : g[i]) if (j != root) d2.insert(j);
vector<set<int> > g1(n); repeat (i,n) for (int j : g[i]) if (d1.count(j)) g1[i].insert(j);
bool ans = false;
for (int i : d2) for (int j : d2) if (i < j) {
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:
cout << (ans ? "YES" : "NO") << endl;
return 0;
}