結果
問題 |
No.1640 簡単な色塗り
|
ユーザー |
|
提出日時 | 2021-08-07 20:56:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,694 bytes |
コンパイル時間 | 2,730 ms |
コンパイル使用メモリ | 194,492 KB |
実行使用メモリ | 96,256 KB |
最終ジャッジ日時 | 2024-06-29 16:58:00 |
合計ジャッジ時間 | 19,746 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 24 WA * 29 |
ソースコード
//#include <atcoder/all> #include <bits/stdc++.h> #include <cmath> using namespace std; //using namespace atcoder; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector<ll>; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector<vector<ll>>; Graph G; vll E; vector<bool> seen; int main() { ll N; cin >> N; Graph G(N); vector<tuple<ll, ll, ll>> edge(N); vll E(N, 0); vector<multiset<ll>> SE(N); map<pair<ll, ll>, queue<ll>> M; rep(i, N) { ll A, B; cin >> A >> B; A--; B--; edge[i] = make_tuple(A, B, -1); M[make_pair(min(A, B), max(A, B))].push(i); SE[A].insert(B); SE[B].insert(A); } queue<ll> Q; rep(i, N) { if (SE[i].size() == 1) { Q.push(i); } else if (SE[i].size() == 0) { cout << "No" << endl; return 0; } } ll k = 0; ll j = 0; while (1) { while (!Q.empty()) { auto p = Q.front(); Q.pop(); ll n = *SE[p].begin(); ll m = M[make_pair(min(p, n), max(p, n))].front(); M[make_pair(min(p, n), max(p, n))].pop(); edge[m] = make_tuple(p, n, p); k++; SE[p].erase(SE[p].find(n)); SE[n].erase(SE[n].find(p)); if(SE[n].size()==0){ cout<<"No"<<endl; return 0; } if (SE[n].size() == 1) { Q.push(n); } } if (k == N) { cout << "Yes" << endl; rep(i, N) { cout << 1+get<2>(edge[i]) << endl; } return 0; } while (SE[j].size() == 0) { j++; } ll p = j; ll n = *SE[p].begin(); ll m = M[make_pair(min(p, n), max(p, n))].front(); M[make_pair(min(p, n), max(p, n))].pop(); edge[m] = make_tuple(p, n, p); k++; SE[p].erase(SE[p].find(n)); SE[n].erase(SE[n].find(p)); if (SE[n].size() == 1) { Q.push(n); } } }