Submission #45661899


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/scc>

using Num = long long int;
std::unordered_map<std::string, Num> names;
Num id {0};

Num reg(const std::string& s) {
    Num sid {0};

    if (names.find(s) == names.end()) {
        sid = id;
        names[s] = sid;
        ++id;
    } else {
        sid = names[s];
    }

    return sid;
}

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

    std::unordered_map<Num, Num> edges;
    std::vector<Num> froms;

    for(decltype(n) i{0}; i<n; ++i) {
        std::string s;
        std::string t;
        is >> s >> t;
        const Num sid = reg(s);
        const Num tid = reg(t);
        edges[sid] = tid;
    }

    atcoder::scc_graph g(id);
    for(const auto& [from, to] : edges) {
        g.add_edge(from, to);
    }

    for(const auto& vec : g.scc()) {
        if (vec.size() > 1) {
            os << "No\n";
            return;
        }
    }

    os << "Yes\n";
    return;
}

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

Submission Info

Submission Time
Task D - Change Usernames
User zettsut
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1087 Byte
Status AC
Exec Time 91 ms
Memory 36208 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 22
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 91 ms 36208 KiB
random_02.txt AC 91 ms 36204 KiB
random_03.txt AC 83 ms 30684 KiB
random_04.txt AC 86 ms 33060 KiB
random_05.txt AC 89 ms 34380 KiB
random_06.txt AC 82 ms 34304 KiB
random_07.txt AC 85 ms 33696 KiB
random_08.txt AC 82 ms 30344 KiB
random_09.txt AC 78 ms 22472 KiB
random_10.txt AC 80 ms 23304 KiB
random_11.txt AC 82 ms 24988 KiB
random_12.txt AC 87 ms 26248 KiB
random_13.txt AC 86 ms 27460 KiB
random_14.txt AC 78 ms 22552 KiB
random_15.txt AC 85 ms 23384 KiB
random_16.txt AC 82 ms 25052 KiB
random_17.txt AC 85 ms 26472 KiB
random_18.txt AC 85 ms 27468 KiB
random_19.txt AC 1 ms 3496 KiB
sample_01.txt AC 1 ms 3604 KiB
sample_02.txt AC 1 ms 3604 KiB
sample_03.txt AC 1 ms 3540 KiB