結果
問題 | No.1640 簡単な色塗り |
ユーザー |
|
提出日時 | 2022-10-22 04:20:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 2,151 ms |
コンパイル使用メモリ | 203,080 KB |
最終ジャッジ日時 | 2025-02-08 10:57:05 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 53 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i = 0; i < (n); i++)using namespace std;using ll = long long;using ld = long double;int main(){cin.tie(0);ios::sync_with_stdio(0);int N; cin >> N;vector<vector<pair<int,int>>> G(N);vector<int> deg(N, 0);rep(i,N) {int a,b; cin >> a >> b; a--; b--;G[a].push_back({b, i});G[b].push_back({a, i});deg[a]++, deg[b]++;}priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;rep(i,N) pq.push({deg[i], i});vector<int> ans(N, -1), used(N, 0);while(!pq.empty()) {auto [d, v] = pq.top(); pq.pop();if(d == deg[v] && !used[v]) {for(auto [to, id] : G[v]) {if(ans[id] == -1) {ans[id] = v;used[v] = 1;deg[v]--, deg[to]--;pq.push({deg[v], v});pq.push({deg[to], to});break;}}}}rep(i,N) {if(used[i] == 0) {cout << "No" << endl;return 0;}}cout << "Yes" << endl;rep(i,N) cout << ans[i] + 1 << "\n";}