Submission #47332193


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>
#include <atcoder/dsu>

namespace {
using ModInt [[maybe_unused]] = atcoder::modint998244353;
using Num [[maybe_unused]] = long long int;
using Vec [[maybe_unused]] = std::vector<Num>;
using Set [[maybe_unused]] = std::set<Num>;
using Mset [[maybe_unused]] = std::multiset<Num>;
using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

template<typename T>
using Q [[maybe_unused]] = std::queue<T>;

template<typename T>
using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

void solve(std::istream& is, std::ostream& os) {
    Num n, m;
    is >> n >> m;

    Vec aset(m, 0);
    for(auto&& x : aset) {
        is >> x;
        --x;
    }

    Vec bset(m, 0);
    for(auto&& x : bset) {
        is >> x;
        --x;
    }

    atcoder::dsu tree(n*2);
    Edges edges(n);
    for(Num i{0}; i<m; ++i) {
        const auto a = aset.at(i);
        const auto b = bset.at(i);
        if (a == b) {
            os << "No\n";
            return;
        }

        const auto a0 = a * 2;
        const auto a1 = a0 | 1;
        const auto b0 = b * 2;
        const auto b1 = b0 | 1;
        tree.merge(a0, b1);
        tree.merge(a1, b0);
    }

    for(Num i{0}; i<n; ++i) {
        const auto i0 = i * 2;
        if (tree.same(i0, i0 | 1)) {
            os << "No\n";
            return;
        }
    }

    os << "Yes\n";
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task D - Good Tuple Problem
User zettsut
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1548 Byte
Status AC
Exec Time 75 ms
Memory 12640 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 27
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 02_random_2_05.txt, 02_random_2_06.txt, 02_random_2_07.txt, 02_random_2_08.txt, 02_random_2_09.txt, 03_tree_00.txt, 04_path_00.txt, 05_corner_00.txt, 05_corner_01.txt, 05_corner_02.txt, 05_corner_03.txt, 05_corner_04.txt, 05_corner_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 4 ms 3452 KiB
00_sample_01.txt AC 1 ms 3380 KiB
00_sample_02.txt AC 1 ms 3472 KiB
00_sample_03.txt AC 1 ms 3540 KiB
01_random_1_00.txt AC 10 ms 5052 KiB
01_random_1_01.txt AC 6 ms 7092 KiB
01_random_1_02.txt AC 10 ms 6036 KiB
01_random_1_03.txt AC 11 ms 8676 KiB
01_random_1_04.txt AC 31 ms 5680 KiB
02_random_2_00.txt AC 25 ms 4980 KiB
02_random_2_01.txt AC 32 ms 5776 KiB
02_random_2_02.txt AC 22 ms 4876 KiB
02_random_2_03.txt AC 28 ms 4976 KiB
02_random_2_04.txt AC 27 ms 4664 KiB
02_random_2_05.txt AC 22 ms 5248 KiB
02_random_2_06.txt AC 30 ms 5696 KiB
02_random_2_07.txt AC 40 ms 6312 KiB
02_random_2_08.txt AC 28 ms 5512 KiB
02_random_2_09.txt AC 41 ms 6260 KiB
03_tree_00.txt AC 71 ms 12640 KiB
04_path_00.txt AC 75 ms 12636 KiB
05_corner_00.txt AC 1 ms 3492 KiB
05_corner_01.txt AC 35 ms 6300 KiB
05_corner_02.txt AC 37 ms 6212 KiB
05_corner_03.txt AC 36 ms 6248 KiB
05_corner_04.txt AC 68 ms 12584 KiB
05_corner_05.txt AC 73 ms 12632 KiB