結果

問題 No.1640 簡単な色塗り
ユーザー rogi52rogi52
提出日時 2022-10-22 04:20:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 207,804 KB
実行使用メモリ 10,540 KB
最終ジャッジ日時 2023-09-14 02:45:04
合計ジャッジ時間 14,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 74 ms
10,516 KB
testcase_05 AC 66 ms
10,468 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 60 ms
7,784 KB
testcase_11 AC 50 ms
6,908 KB
testcase_12 AC 41 ms
6,504 KB
testcase_13 AC 102 ms
10,040 KB
testcase_14 AC 106 ms
9,940 KB
testcase_15 AC 30 ms
5,528 KB
testcase_16 AC 38 ms
6,000 KB
testcase_17 AC 86 ms
8,888 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 42 ms
6,596 KB
testcase_20 AC 61 ms
7,588 KB
testcase_21 AC 45 ms
6,784 KB
testcase_22 AC 5 ms
4,384 KB
testcase_23 AC 66 ms
8,048 KB
testcase_24 AC 16 ms
4,532 KB
testcase_25 AC 42 ms
6,608 KB
testcase_26 AC 72 ms
8,436 KB
testcase_27 AC 26 ms
5,512 KB
testcase_28 AC 92 ms
9,824 KB
testcase_29 AC 68 ms
8,404 KB
testcase_30 AC 11 ms
4,376 KB
testcase_31 AC 97 ms
10,296 KB
testcase_32 AC 87 ms
9,352 KB
testcase_33 AC 47 ms
7,132 KB
testcase_34 AC 66 ms
8,312 KB
testcase_35 AC 52 ms
7,184 KB
testcase_36 AC 10 ms
4,384 KB
testcase_37 AC 14 ms
4,672 KB
testcase_38 AC 83 ms
9,484 KB
testcase_39 AC 30 ms
6,016 KB
testcase_40 AC 31 ms
6,036 KB
testcase_41 AC 66 ms
8,372 KB
testcase_42 AC 37 ms
6,384 KB
testcase_43 AC 37 ms
6,552 KB
testcase_44 AC 35 ms
6,508 KB
testcase_45 AC 26 ms
5,608 KB
testcase_46 AC 13 ms
4,452 KB
testcase_47 AC 7 ms
4,380 KB
testcase_48 AC 84 ms
9,672 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 107 ms
10,540 KB
testcase_53 AC 112 ms
10,484 KB
07_evil_01.txt AC 281 ms
18,908 KB
07_evil_02.txt AC 473 ms
27,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
}
0