Submission #7763346


Source Code Expand

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

using i64 = int64_t;

struct Edge{
    int from, to;
};

struct Node{
    int num;
    vector<int> visited;
};

using Graph = vector<vector<Edge>>;

int main(){
    int n, m;
    cin >> n >> m;
    Graph graph(n+1, vector<Edge>());
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        graph[a].push_back({a, b});
    }

    vector<int> ans;
    for(int i=1;i<=n;++i){
        queue<Node> que;
        deque<bool> visited(n+1);
        for(auto e: graph[i]){
            que.push({e.to, vector<int>({e.to})});
            visited[e.to] = true;
        }
        while(!que.empty()){
            auto cur = que.front(); que.pop();
            if(cur.num == i){
                if(ans.size() == 0 || cur.visited.size() < ans.size()){
                    ans = cur.visited;
                }
                break;
            }
            for(auto e: graph[cur.num]){
                if(visited[e.to])continue;
                auto v = cur.visited;
                v.push_back(e.to);
                que.push({e.to, v});
            }
        }
    }

    if(ans.size() == 0)cout << -1 << endl;
    else{
        cout << ans.size() << endl;
        for(auto e: ans){
            cout << e << endl;
        }
    }

    return 0;
}

Submission Info

Submission Time
Task F - Pure
User nicklaw296
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1358 Byte
Status TLE
Exec Time 2149 ms
Memory 743920 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 19
TLE × 14
Set Name Test Cases
Sample Sample_01.txt, Sample_02.txt, Sample_03.txt
Subtask1 Sample_01.txt, Sample_02.txt, Sample_03.txt, case_01.txt, case_02.txt, case_03.txt, case_04.txt, case_05.txt, case_06.txt, case_07.txt, case_08.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_14.txt, case_15.txt, case_16.txt, case_17.txt, case_18.txt, case_19.txt, case_20.txt, case_21.txt, case_22.txt, case_23.txt, case_24.txt, case_25.txt, case_26.txt, case_27.txt, case_28.txt, case_29.txt, case_30.txt
Case Name Status Exec Time Memory
Sample_01.txt AC 1 ms 256 KB
Sample_02.txt AC 1 ms 256 KB
Sample_03.txt AC 1 ms 256 KB
case_01.txt TLE 2146 ms 712764 KB
case_02.txt TLE 2145 ms 691616 KB
case_03.txt TLE 2146 ms 704128 KB
case_04.txt TLE 2143 ms 661552 KB
case_05.txt TLE 2145 ms 683524 KB
case_06.txt TLE 2145 ms 706728 KB
case_07.txt TLE 2145 ms 693264 KB
case_08.txt TLE 2147 ms 717444 KB
case_09.txt TLE 2149 ms 743920 KB
case_10.txt TLE 2146 ms 709132 KB
case_11.txt AC 5 ms 256 KB
case_12.txt AC 5 ms 256 KB
case_13.txt AC 5 ms 256 KB
case_14.txt AC 5 ms 256 KB
case_15.txt AC 5 ms 256 KB
case_16.txt AC 1 ms 256 KB
case_17.txt AC 2 ms 256 KB
case_18.txt AC 2 ms 256 KB
case_19.txt TLE 2103 ms 4616 KB
case_20.txt AC 915 ms 808 KB
case_21.txt AC 961 ms 1296 KB
case_22.txt TLE 2103 ms 7484 KB
case_23.txt TLE 2103 ms 29868 KB
case_24.txt TLE 2104 ms 10380 KB
case_25.txt AC 533 ms 384 KB
case_26.txt AC 524 ms 384 KB
case_27.txt AC 528 ms 384 KB
case_28.txt AC 529 ms 384 KB
case_29.txt AC 533 ms 384 KB
case_30.txt AC 109 ms 256 KB