# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
781261 | 2023-07-13T01:26:47 Z | makanhulia | Naboj (COCI22_naboj) | C++17 | 1 ms | 436 KB |
#include <bits/stdc++.h> using namespace std; const int N=15; int n, m; vector <int> ls[N], topo; int in[N], bio[N]; queue <int> Q; void dfs(int node) { if (bio[node] == 1) { printf("-1\n"); exit(0); } if (bio[node] == 2) return; bio[node] = 1; for (int x:ls[node]) dfs(x); bio[node] = 2; } void solve() { for (int i=1; i<=n; ++i) { if (!bio[i]) dfs(i); if (in[i] == 0) { Q.push(i); } } while (!Q.empty()) { int node = Q.front(); Q.pop(); topo.push_back(node); for (int sus:ls[node]) { in[sus]--; if (in[sus] == 0) Q.push(sus); } } printf("%d\n", (int)topo.size()); for (int x:topo) printf("%d 0\n", x); } void load() { scanf("%d %d", &n, &m); for (int i=0; i<m; ++i) { int a, b; scanf("%d %d", &a, &b); ls[a].push_back(b); in[b]++; } } int main() { load(); solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 296 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 436 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 296 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Runtime error | 1 ms | 436 KB | Execution killed with signal 11 |
16 | Halted | 0 ms | 0 KB | - |