Submission #7763628


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});
                visited[e.to] = true;
            }
        }
    }

    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 600
Code Size 1397 Byte
Status AC
Exec Time 551 ms
Memory 384 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 33
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 AC 78 ms 384 KB
case_02.txt AC 85 ms 384 KB
case_03.txt AC 81 ms 384 KB
case_04.txt AC 88 ms 384 KB
case_05.txt AC 78 ms 384 KB
case_06.txt AC 82 ms 384 KB
case_07.txt AC 82 ms 384 KB
case_08.txt AC 84 ms 384 KB
case_09.txt AC 85 ms 384 KB
case_10.txt AC 82 ms 384 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 AC 286 ms 384 KB
case_20.txt AC 253 ms 384 KB
case_21.txt AC 186 ms 384 KB
case_22.txt AC 271 ms 256 KB
case_23.txt AC 233 ms 384 KB
case_24.txt AC 229 ms 384 KB
case_25.txt AC 548 ms 384 KB
case_26.txt AC 535 ms 384 KB
case_27.txt AC 535 ms 384 KB
case_28.txt AC 543 ms 384 KB
case_29.txt AC 551 ms 384 KB
case_30.txt AC 112 ms 256 KB