結果

問題 No.1640 簡単な色塗り
ユーザー KoDKoD
提出日時 2021-08-06 21:44:22
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 2,938 bytes
コンパイル時間 3,398 ms
コンパイル使用メモリ 253,780 KB
実行使用メモリ 18,608 KB
最終ジャッジ日時 2023-09-12 01:48:07
合計ジャッジ時間 13,610 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 39 ms
14,128 KB
testcase_05 AC 42 ms
18,608 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 38 ms
9,924 KB
testcase_11 AC 32 ms
8,524 KB
testcase_12 AC 28 ms
8,000 KB
testcase_13 AC 68 ms
13,260 KB
testcase_14 AC 66 ms
13,352 KB
testcase_15 AC 19 ms
6,808 KB
testcase_16 AC 23 ms
7,472 KB
testcase_17 AC 52 ms
11,736 KB
testcase_18 AC 5 ms
4,384 KB
testcase_19 AC 26 ms
8,088 KB
testcase_20 AC 39 ms
9,584 KB
testcase_21 AC 30 ms
8,520 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 41 ms
10,196 KB
testcase_24 AC 10 ms
5,184 KB
testcase_25 AC 27 ms
8,100 KB
testcase_26 AC 49 ms
11,112 KB
testcase_27 AC 17 ms
6,452 KB
testcase_28 AC 65 ms
12,752 KB
testcase_29 AC 48 ms
10,760 KB
testcase_30 AC 10 ms
5,236 KB
testcase_31 AC 86 ms
16,216 KB
testcase_32 AC 68 ms
14,876 KB
testcase_33 AC 42 ms
11,484 KB
testcase_34 AC 57 ms
14,112 KB
testcase_35 AC 42 ms
11,448 KB
testcase_36 AC 9 ms
5,364 KB
testcase_37 AC 13 ms
6,204 KB
testcase_38 AC 73 ms
14,900 KB
testcase_39 AC 26 ms
8,308 KB
testcase_40 AC 29 ms
8,328 KB
testcase_41 AC 58 ms
13,280 KB
testcase_42 AC 30 ms
8,776 KB
testcase_43 AC 32 ms
9,440 KB
testcase_44 AC 32 ms
9,316 KB
testcase_45 AC 22 ms
8,024 KB
testcase_46 AC 10 ms
5,556 KB
testcase_47 AC 7 ms
4,744 KB
testcase_48 AC 75 ms
16,460 KB
testcase_49 AC 4 ms
4,384 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 93 ms
18,316 KB
testcase_53 AC 89 ms
17,060 KB
07_evil_01.txt AC 185 ms
26,160 KB
07_evil_02.txt AC 291 ms
37,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { ++itr; }
        constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

template <class F> struct RecursiveLambda : private F {
    explicit constexpr RecursiveLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> constexpr decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class F> constexpr decltype(auto) rec_lambda(F&& f) {
    using G = std::decay_t<F>;
    return RecursiveLambda<G>(std::forward<G>(f));
}

template <class T> using Vec = std::vector<T>;

void main_() {
    usize N;
    std::cin >> N;
    Vec<usize> A(N), B(N);
    Vec<Vec<std::pair<usize, usize>>> graph(N);
    for (const auto i : rep(0, N)) {
        std::cin >> A[i] >> B[i];
        A[i] -= 1;
        B[i] -= 1;
        graph[A[i]].emplace_back(B[i], i);
        graph[B[i]].emplace_back(A[i], i);
    }
    Vec<usize> depth(N), pedge(N), select(N);
    for (const auto root : rep(0, N)) {
        if (depth[root] == 0) {
            usize rev = N;
            depth[root] = 1;
            pedge[root] = N;
            rec_lambda([&](auto&& dfs, const usize u) -> void {
                for (const auto& [v, e] : graph[u]) {
                    if (e == pedge[u]) {
                        continue;
                    }
                    select[e] = v;
                    if (depth[v] > 0) {
                        rev = e;
                    } else {
                        depth[v] = depth[u] + 1;
                        pedge[v] = e;
                        dfs(v);
                    }
                }
            })(root);
            if (rev == N) {
                std::cout << "No\n";
                return;
            }
            while (rev != N) {
                const auto t = (depth[A[rev]] < depth[B[rev]] ? A[rev] : B[rev]);
                select[rev] = t;
                rev = pedge[t];
            }
        }
    }
    std::cout << "Yes\n";
    for (const auto x : select) {
        std::cout << x + 1 << '\n';
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    main_();
    return 0;
}
0