# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
852270 | 2023-09-21T14:06:57 Z | Trisanu_Das | Naboj (COCI22_naboj) | C++17 | 129 ms | 13504 KB |
#include <bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; int deg[n + 1], u, v; memset(deg, 0, sizeof(deg)); vector<int> adj[n + 1]; while(m--){ cin >> v >> u; adj[u].push_back(u); deg[u]++; } vector<int> toposort; queue<int> q; for(int i = 1; i < n + 1; i++) if(deg[i] == 0) q.push(i); while(!q.empty()){ int u = q.front(); q.pop(); toposort.push_back(u); for(int v : adj[u]){ deg[v]--; if(deg[v] == 0) q.push(v); } } if(toposort.size() != n) cout << -1 << '\n'; else{ cout << n << '\n'; for(auto u : toposort) cout << u << ' ' << 0 << '\n'; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 544 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Incorrect | 0 ms | 344 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 129 ms | 13504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 544 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 344 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Incorrect | 0 ms | 344 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |