Submission #7761434
Source Code Expand
Copy
#include<bits/stdc++.h> using namespace std; using i64 = int64_t; struct Edge{ int from, to; }; struct Node{ int num; set<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}); } set<int> ans; for(int i=1;i<=n;++i){ queue<Node> que; for(auto e: graph[i]){ que.push({e.to, set<int>({e.to})}); } 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(cur.visited.count(e.to))continue; auto st = cur.visited; st.insert(e.to); que.push({e.to, st}); } } } 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 | 1289 Byte |
Status | TLE |
Exec Time | 2135 ms |
Memory | 524208 KB |
Judge Result
Set Name | Sample | Subtask1 | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 600 | ||||||
Status |
|
|
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 | 2132 ms | 475196 KB |
case_02.txt | TLE | 2133 ms | 500024 KB |
case_03.txt | TLE | 2135 ms | 524208 KB |
case_04.txt | TLE | 2133 ms | 495548 KB |
case_05.txt | TLE | 2134 ms | 503596 KB |
case_06.txt | TLE | 2134 ms | 510520 KB |
case_07.txt | TLE | 2134 ms | 503056 KB |
case_08.txt | TLE | 2135 ms | 520240 KB |
case_09.txt | TLE | 2133 ms | 506656 KB |
case_10.txt | TLE | 2133 ms | 493628 KB |
case_11.txt | AC | 8 ms | 256 KB |
case_12.txt | AC | 7 ms | 384 KB |
case_13.txt | AC | 8 ms | 256 KB |
case_14.txt | AC | 6 ms | 256 KB |
case_15.txt | AC | 7 ms | 384 KB |
case_16.txt | AC | 1 ms | 256 KB |
case_17.txt | AC | 1 ms | 256 KB |
case_18.txt | AC | 23 ms | 780 KB |
case_19.txt | TLE | 2104 ms | 3456 KB |
case_20.txt | TLE | 2103 ms | 1408 KB |
case_21.txt | TLE | 2103 ms | 1932 KB |
case_22.txt | TLE | 2103 ms | 3200 KB |
case_23.txt | TLE | 2103 ms | 1024 KB |
case_24.txt | TLE | 2103 ms | 1108 KB |
case_25.txt | TLE | 2103 ms | 512 KB |
case_26.txt | TLE | 2103 ms | 512 KB |
case_27.txt | TLE | 2103 ms | 512 KB |
case_28.txt | TLE | 2103 ms | 512 KB |
case_29.txt | TLE | 2103 ms | 512 KB |
case_30.txt | TLE | 2103 ms | 384 KB |