結果
問題 |
No.483 マッチ並べ
|
ユーザー |
![]() |
提出日時 | 2017-02-11 00:17:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,360 bytes |
コンパイル時間 | 1,158 ms |
コンパイル使用メモリ | 73,848 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-29 11:27:53 |
合計ジャッジ時間 | 2,532 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 31 WA * 22 |
ソースコード
#include <iostream> #include <map> #include <cstring> #include <vector> using namespace std; using P = pair<int, int>; const int NUM = 114514; vector<int> graph[NUM]; int color[NUM]; bool dfs(int v, int c, int prev) { color[v] = c; for (int to : graph[v]) { if (to == prev) continue; if (color[to] < 0) { if (!dfs(to, 1, v)) return false; } else if (color[to] == c) { return false; } } return true; } int main() { int n; cin >> n; memset(color, -1, sizeof(color)); int id = 0; map<P, int> dict; for (int i = 0; i < n; i++) { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; P p1 = make_pair(r1, c1), p2 = make_pair(r2, c2); int id1, id2; if (dict.find(p1) == dict.end()) { dict[p1] = id; id++; } if (dict.find(p2) == dict.end()) { dict[p2] = id; id++; } id1 = dict[p1]; id2 = dict[p2]; graph[id1].push_back(id2); graph[id2].push_back(id1); } /* for (int v = 0; v < id; v++) { if (color[v] == -1) { if (!dfs(v, 0, -1)) { cout << "NO" << endl; return 0; } } } */ cout << "YES" << endl; return 0; }