結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2016-10-18 19:55:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,507 bytes |
コンパイル時間 | 2,110 ms |
コンパイル使用メモリ | 183,996 KB |
実行使用メモリ | 14,336 KB |
最終ジャッジ日時 | 2024-11-22 12:39:06 |
合計ジャッジ時間 | 3,633 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define repeat(i, j, k) for(int i = (j); i < (int)(k); i++) #define all(v) v.begin(),v.end() template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; } class Solver { public: vector<set<int>> E; bool solve() { int N, M; cin >> N >> M; E.resize(N); rep(i, M) { int a, b; cin >> a >> b; a--, b--; E[a].insert(b); E[b].insert(a); } map<int, set<int>> reachable_two; // mp[i] : 0から2回でiに達する道 (全ての場合の数, 中間ノード) for(auto a : E[0]) { for(auto b : E[a]) { reachable_two[b].insert(a); } } bool flg = false; for(auto a = reachable_two.begin(); a != reachable_two.end(); a++) { for(auto b = reachable_two.begin(); b != a; b++) { if(E[a->first].count(b->first)) { decltype(a) aa, bb; aa = a; bb = b; if(aa->second.size() > bb->second.size()) swap(aa, bb); int va = a->first, vb = b->first; // node int a_road_num = aa->second.size() - (aa->second.count(vb)); int b_road_num = bb->second.size() - (aa->second.count(va)); if(a_road_num == 0 or b_road_num == 0) continue; else if(a_road_num >= 2 and b_road_num >= 2) flg |= true; else if(b_road_num >= 2) { assert(a_road_num == 1); int node = *a->second.begin(); flg |= not b->second.count(node); } else { assert(a_road_num == 1 and b_road_num == 1); int node_a = *a->second.begin(); int node_b = *b->second.begin(); flg |= (not b->second.count(node_a) and not a->second.count(node_b)); } } if(flg) goto END; } } END:; cout << (flg ? "YES" : "NO") << endl; return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }