結果

問題 No.1640 簡単な色塗り
ユーザー KudeKude
提出日時 2021-08-06 22:15:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,711 bytes
コンパイル時間 4,883 ms
コンパイル使用メモリ 265,404 KB
実行使用メモリ 13,708 KB
最終ジャッジ日時 2023-09-12 02:11:17
合計ジャッジ時間 14,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 37 ms
9,096 KB
testcase_05 AC 42 ms
13,708 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 37 ms
7,024 KB
testcase_11 AC 28 ms
6,372 KB
testcase_12 AC 26 ms
6,056 KB
testcase_13 AC 68 ms
9,168 KB
testcase_14 AC 61 ms
9,092 KB
testcase_15 AC 17 ms
5,296 KB
testcase_16 AC 20 ms
5,748 KB
testcase_17 AC 49 ms
8,040 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 24 ms
6,052 KB
testcase_20 AC 31 ms
6,840 KB
testcase_21 AC 26 ms
6,284 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 39 ms
7,500 KB
testcase_24 AC 9 ms
4,388 KB
testcase_25 AC 25 ms
5,940 KB
testcase_26 AC 41 ms
7,516 KB
testcase_27 AC 17 ms
5,236 KB
testcase_28 AC 59 ms
8,836 KB
testcase_29 AC 44 ms
7,572 KB
testcase_30 AC 7 ms
4,516 KB
testcase_31 AC 70 ms
10,700 KB
testcase_32 AC 59 ms
10,156 KB
testcase_33 AC 36 ms
8,124 KB
testcase_34 AC 47 ms
10,188 KB
testcase_35 AC 34 ms
8,348 KB
testcase_36 AC 7 ms
4,540 KB
testcase_37 AC 11 ms
5,252 KB
testcase_38 AC 58 ms
10,224 KB
testcase_39 AC 19 ms
6,340 KB
testcase_40 AC 19 ms
6,260 KB
testcase_41 AC 49 ms
9,296 KB
testcase_42 AC 24 ms
6,464 KB
testcase_43 AC 25 ms
7,064 KB
testcase_44 AC 23 ms
7,112 KB
testcase_45 AC 18 ms
6,268 KB
testcase_46 AC 9 ms
4,756 KB
testcase_47 AC 6 ms
4,380 KB
testcase_48 AC 66 ms
11,684 KB
testcase_49 AC 3 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 80 ms
12,828 KB
testcase_53 AC 79 ms
11,552 KB
07_evil_01.txt AC 170 ms
16,420 KB
07_evil_02.txt AC 283 ms
22,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<P>> to(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].emplace_back(b, i);
        to[b].emplace_back(a, i);
    }
    vector<char> visited(n), col(n), used(n);
    VI ans(n);
    auto dfs = [&](auto&& self, int u) -> bool {
        visited[u] = true;
        bool ret = false;
        for(auto [v, i]: to[u]) if (!used[i]) {
            used[i] = true;
            if (visited[v]) {
                ans[i] = u;
                col[u] = true;
                ret = true;
                continue;
            }
            bool r = self(self, v);
            if (r) {
                ans[i] = u;
                col[u] = true;
                ret = true;
            } else {
                ans[i] = v;
                col[v] = true;
            }
        }
        return ret;
    };
    rep(i, n) if (!visited[i]) dfs(dfs, i);
    bool ok = true;
    rep(i, n) ok &= col[i];
    if (!ok) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    rep(i, n) cout << ans[i] + 1 << '\n';
}
0