結果

問題 No.1640 簡単な色塗り
ユーザー rogi52rogi52
提出日時 2022-10-22 04:06:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,717 bytes
コンパイル時間 3,266 ms
コンパイル使用メモリ 217,252 KB
実行使用メモリ 34,928 KB
最終ジャッジ日時 2023-09-14 02:38:20
合計ジャッジ時間 20,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 181 ms
22,468 KB
testcase_05 AC 168 ms
33,792 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 119 ms
15,104 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 27 ms
7,304 KB
testcase_31 AC 298 ms
33,088 KB
testcase_32 AC 230 ms
28,532 KB
testcase_33 AC 131 ms
19,900 KB
testcase_34 AC 204 ms
25,384 KB
testcase_35 AC 136 ms
20,564 KB
testcase_36 AC 26 ms
7,284 KB
testcase_37 AC 37 ms
9,040 KB
testcase_38 AC 245 ms
29,428 KB
testcase_39 AC 87 ms
14,876 KB
testcase_40 AC 78 ms
14,180 KB
testcase_41 AC 175 ms
23,884 KB
testcase_42 AC 93 ms
15,996 KB
testcase_43 AC 106 ms
17,504 KB
testcase_44 AC 98 ms
16,252 KB
testcase_45 AC 66 ms
13,700 KB
testcase_46 AC 30 ms
8,000 KB
testcase_47 AC 18 ms
6,348 KB
testcase_48 AC 247 ms
30,752 KB
testcase_49 AC 7 ms
4,676 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 416 ms
34,900 KB
testcase_53 AC 418 ms
34,928 KB
07_evil_01.txt WA -
07_evil_02.txt WA -
権限があれば一括ダウンロードができます

ソースコード

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<int> A(N), B(N);
    map<pair<int,int>,int> exist;
    rep(i,N) cin >> A[i] >> B[i], A[i]--, B[i]--, exist[{A[i], B[i]}] = exist[{B[i], A[i]}] = 1;

    vector<vector<int>> G(N);
    vector<int> deg(N, 0);
    rep(i,N) {
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
        deg[A[i]]++, deg[B[i]]++;
    }
    queue<int> q;
    vector<int> used(N, 0);
    rep(i,N) if(deg[i] == 1) {
        q.push(i);
        deg[i] -= 1;
        used[i] = 1;
    }
    map<pair<int,int>,int> ans;
    while(!q.empty()) {
        int v = q.front(); q.pop();
        for(int to : G[v]) {
            if(!used[to]) {
                ans[{v, to}] = ans[{to, v}] = v;
                if(--deg[to] == 1) {
                    q.push(to);
                    used[to] = 1;
                }
            }
        }
    }

    rep(i,N) if(!used[i]) {
        vector<int> vs;
        function<void(int)> dfs = [&](int v) -> void {
            vs.push_back(v);
            used[v] = 1;
            for(int to : G[v]) if(!used[to]) dfs(to);
        }; dfs(i);

        if(vs.size() == 1u) {
            if(exist[{i, i}]) {
                ans[{i, i}] = i;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
        rep(k,vs.size()) ans[{vs[k], vs[(k + 1) % (int)vs.size()]}] = vs[k];
    }

    cout << "Yes" << endl;
    rep(i,N) {
        cout << ans[{A[i], B[i]}] + 1 << "\n";
        ans[{A[i], B[i]}] ^= (A[i] ^ B[i]);
    }
}
0