# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
782483 | 2023-07-14T03:01:00 Z | kebine | Naboj (COCI22_naboj) | C++17 | 179 ms | 26292 KB |
# include <bits/stdc++.h> # define int long long # define vi vector<int> # define pb push_back # define pii pair<int, int> # define fi first # define se second # define endl '\n' # define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, m, rec[500005]; vi adj[500005]; bool vis[500005]; void solve() { cin >> n >> m; for(int i=1; i<=m; i++) { int a, b; cin >> a >> b; adj[b].pb(a); rec[a]++; } queue<int> q; vi v; for(int i=1; i<=n; i++) { if(rec[i]==0) { q.push(i); v.pb(i); } } while(!q.empty()) { int cur=q.front(); q.pop(); for(int i : adj[cur]) { if(vis[i]) continue; rec[i]--; if(rec[i]==0) { q.push(i); vis[i]=1; v.pb(i); } } } if(v.size()<n) { cout << -1 << endl; return; } cout << n << endl; for(int i : v) cout << i << " " << 1 << endl; } signed main() { jess; solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 11988 KB | Output is correct |
2 | Correct | 5 ms | 11988 KB | Output is correct |
3 | Correct | 5 ms | 11988 KB | Output is correct |
4 | Correct | 5 ms | 11988 KB | Output is correct |
5 | Correct | 5 ms | 11988 KB | Output is correct |
6 | Correct | 5 ms | 11988 KB | Output is correct |
7 | Correct | 5 ms | 11988 KB | Output is correct |
8 | Correct | 5 ms | 11988 KB | Output is correct |
9 | Correct | 6 ms | 12076 KB | Output is correct |
10 | Correct | 5 ms | 11964 KB | Output is correct |
11 | Correct | 5 ms | 12080 KB | Output is correct |
12 | Correct | 5 ms | 12080 KB | Output is correct |
13 | Correct | 5 ms | 11988 KB | Output is correct |
14 | Correct | 6 ms | 11988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 86 ms | 22020 KB | Output is correct |
2 | Correct | 88 ms | 22104 KB | Output is correct |
3 | Correct | 41 ms | 17336 KB | Output is correct |
4 | Correct | 84 ms | 22092 KB | Output is correct |
5 | Correct | 85 ms | 22004 KB | Output is correct |
6 | Correct | 79 ms | 22088 KB | Output is correct |
7 | Correct | 91 ms | 22104 KB | Output is correct |
8 | Correct | 61 ms | 19788 KB | Output is correct |
9 | Correct | 81 ms | 22096 KB | Output is correct |
10 | Correct | 82 ms | 22096 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 11988 KB | Output is correct |
2 | Correct | 5 ms | 11988 KB | Output is correct |
3 | Correct | 5 ms | 11988 KB | Output is correct |
4 | Correct | 5 ms | 11988 KB | Output is correct |
5 | Correct | 5 ms | 11988 KB | Output is correct |
6 | Correct | 5 ms | 11988 KB | Output is correct |
7 | Correct | 5 ms | 11988 KB | Output is correct |
8 | Correct | 5 ms | 11988 KB | Output is correct |
9 | Correct | 6 ms | 12076 KB | Output is correct |
10 | Correct | 5 ms | 11964 KB | Output is correct |
11 | Correct | 5 ms | 12080 KB | Output is correct |
12 | Correct | 5 ms | 12080 KB | Output is correct |
13 | Correct | 5 ms | 11988 KB | Output is correct |
14 | Correct | 6 ms | 11988 KB | Output is correct |
15 | Correct | 86 ms | 22020 KB | Output is correct |
16 | Correct | 88 ms | 22104 KB | Output is correct |
17 | Correct | 41 ms | 17336 KB | Output is correct |
18 | Correct | 84 ms | 22092 KB | Output is correct |
19 | Correct | 85 ms | 22004 KB | Output is correct |
20 | Correct | 79 ms | 22088 KB | Output is correct |
21 | Correct | 91 ms | 22104 KB | Output is correct |
22 | Correct | 61 ms | 19788 KB | Output is correct |
23 | Correct | 81 ms | 22096 KB | Output is correct |
24 | Correct | 82 ms | 22096 KB | Output is correct |
25 | Correct | 88 ms | 20292 KB | Output is correct |
26 | Correct | 94 ms | 21232 KB | Output is correct |
27 | Correct | 93 ms | 21516 KB | Output is correct |
28 | Correct | 125 ms | 22580 KB | Output is correct |
29 | Correct | 74 ms | 21844 KB | Output is correct |
30 | Correct | 114 ms | 22496 KB | Output is correct |
31 | Correct | 21 ms | 13860 KB | Output is correct |
32 | Correct | 90 ms | 24492 KB | Output is correct |
33 | Correct | 146 ms | 25756 KB | Output is correct |
34 | Correct | 106 ms | 24508 KB | Output is correct |
35 | Correct | 143 ms | 25900 KB | Output is correct |
36 | Correct | 89 ms | 24544 KB | Output is correct |
37 | Correct | 138 ms | 25264 KB | Output is correct |
38 | Correct | 116 ms | 24860 KB | Output is correct |
39 | Correct | 179 ms | 25736 KB | Output is correct |
40 | Correct | 128 ms | 25092 KB | Output is correct |
41 | Correct | 123 ms | 25112 KB | Output is correct |
42 | Correct | 177 ms | 26276 KB | Output is correct |
43 | Correct | 102 ms | 24532 KB | Output is correct |
44 | Correct | 153 ms | 26292 KB | Output is correct |
45 | Correct | 101 ms | 24464 KB | Output is correct |
46 | Correct | 148 ms | 25188 KB | Output is correct |