結果

問題 No.1640 簡単な色塗り
ユーザー rogi52rogi52
提出日時 2022-10-22 04:03:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,496 bytes
コンパイル時間 5,453 ms
コンパイル使用メモリ 215,360 KB
実行使用メモリ 22,640 KB
最終ジャッジ日時 2023-09-14 02:36:46
合計ジャッジ時間 20,865 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 103 ms
21,368 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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 14 ms
5,440 KB
testcase_31 AC 158 ms
21,080 KB
testcase_32 AC 119 ms
17,904 KB
testcase_33 AC 62 ms
12,792 KB
testcase_34 AC 107 ms
16,636 KB
testcase_35 AC 64 ms
13,404 KB
testcase_36 AC 13 ms
5,448 KB
testcase_37 AC 17 ms
6,508 KB
testcase_38 AC 123 ms
18,408 KB
testcase_39 AC 46 ms
10,116 KB
testcase_40 AC 38 ms
9,384 KB
testcase_41 AC 77 ms
14,796 KB
testcase_42 AC 54 ms
10,428 KB
testcase_43 AC 60 ms
11,852 KB
testcase_44 AC 45 ms
10,660 KB
testcase_45 AC 33 ms
9,388 KB
testcase_46 AC 15 ms
6,008 KB
testcase_47 AC 10 ms
5,300 KB
testcase_48 AC 124 ms
19,420 KB
testcase_49 AC 5 ms
4,380 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 291 ms
22,640 KB
testcase_53 AC 291 ms
22,512 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);
    rep(i,N) cin >> A[i] >> B[i], A[i]--, B[i]--;

    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) { 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