Submission #73513056


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n + 1);
    for (int i = 1, x, y; i <= m; i++) {
        cin >> x >> y;
        g[x].push_back(y);
    }
    for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());
    vector<int> p(n + 1, 0);
    
    int num = 1;
    vector<bool> f(n + 1, false); 
    set<int> h;
    h.insert(1), f[1] = true;
    
    set<int> ans;
    for (int x : g[1]) if (x != 1) ans.insert(x);
    for (int i = 1; i <= n; i++) {
        set<int> a, d;
        for (int x : h) {
            int sz = g[x].size();
            while (p[x] < sz && g[x][p[x]] <= i) {
                int y = g[x][p[x]++];
                if (!f[y]) f[y] = true, num++, a.insert(y);
            }
            if (p[x] == sz) d.insert(x);
        }
        if (f[i]) {
            if (ans.count(i)) ans.erase(i);
            queue<int> q;
            q.push(i);
            while (!q.empty()) {
                int x = q.front(); q.pop();
                int sz = g[x].size();
                while (p[x] < sz && g[x][p[x]] <= i) {
                    int y = g[x][p[x]++];
                    if (!f[y]) f[y] = true, num++, a.insert(y), q.push(y);
                }
                if (p[x] == sz) d.insert(x);
            }
        }
        for (int x : a) {
            h.insert(x);
            for (int j = p[x]; j < (int) g[x].size(); j++) ans.insert(g[x][j]);
        }
        for (int x : d) h.erase(x);
        
//        cout << "i= " << i << ", num= " << num << '\n';
        if (num == i) {
            cout << ans.size() << '\n';
        } else {
            cout << -1 << '\n';
        }
    }
    
    return 0;
}

Submission Info

Submission Time
Task F - Reachable Set 2
User liangsheng
Language C++23 (GCC 15.2.0)
Score 0
Code Size 1838 Byte
Status TLE
Exec Time > 2000 ms
Memory 63192 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 35
TLE × 20
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, random_00.txt, 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, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3604 KiB
example_01.txt AC 1 ms 3564 KiB
hand_00.txt AC 87 ms 20952 KiB
hand_01.txt TLE > 2000 ms 17352 KiB
hand_02.txt AC 140 ms 26804 KiB
hand_03.txt AC 139 ms 26828 KiB
hand_04.txt AC 27 ms 5720 KiB
hand_05.txt AC 59 ms 12100 KiB
hand_06.txt AC 137 ms 26884 KiB
hand_07.txt AC 107 ms 23880 KiB
hand_08.txt AC 12 ms 11604 KiB
hand_09.txt AC 1 ms 3604 KiB
hand_10.txt AC 1 ms 3532 KiB
hand_11.txt AC 26 ms 12872 KiB
hand_12.txt TLE > 2000 ms 18892 KiB
hand_13.txt TLE > 2000 ms 18964 KiB
hand_14.txt AC 82 ms 20956 KiB
hand_15.txt AC 234 ms 63192 KiB
hand_16.txt AC 82 ms 20824 KiB
random_00.txt AC 32 ms 5016 KiB
random_01.txt AC 575 ms 6144 KiB
random_02.txt TLE > 2000 ms 12612 KiB
random_03.txt AC 34 ms 5460 KiB
random_04.txt AC 71 ms 5640 KiB
random_05.txt AC 54 ms 15704 KiB
random_06.txt TLE > 2000 ms 19620 KiB
random_07.txt TLE > 2000 ms 19544 KiB
random_08.txt TLE > 2000 ms 19544 KiB
random_09.txt AC 25 ms 5444 KiB
random_10.txt TLE > 2000 ms 6912 KiB
random_11.txt TLE > 2000 ms 15012 KiB
random_12.txt AC 1 ms 3616 KiB
random_13.txt AC 99 ms 4376 KiB
random_14.txt TLE > 2000 ms 17432 KiB
random_15.txt AC 1 ms 3732 KiB
random_16.txt AC 20 ms 4440 KiB
random_17.txt AC 180 ms 12504 KiB
random_18.txt AC 1 ms 3764 KiB
random_19.txt AC 17 ms 4756 KiB
random_20.txt AC 387 ms 14968 KiB
random_21.txt AC 30 ms 5204 KiB
random_22.txt AC 1079 ms 6500 KiB
random_23.txt TLE > 2000 ms 14172 KiB
random_24.txt TLE > 2000 ms 14740 KiB
random_25.txt TLE > 2000 ms 14676 KiB
random_26.txt TLE > 2000 ms 14712 KiB
random_27.txt TLE > 2000 ms 12612 KiB
random_28.txt TLE > 2000 ms 12544 KiB
random_29.txt TLE > 2000 ms 12616 KiB
random_30.txt TLE > 2000 ms 8408 KiB
random_31.txt TLE > 2000 ms 8520 KiB
random_32.txt TLE > 2000 ms 8516 KiB
random_33.txt AC 1076 ms 6472 KiB
random_34.txt AC 1019 ms 6468 KiB
random_35.txt AC 1047 ms 6472 KiB