# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
852284 | Trisanu_Das | Naboj (COCI22_naboj) | C++17 | 248 ms | 20268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> deg(n + 1), adj[n + 1], topo;
int a, b;
while(m--){
cin >> a >> b;
deg[b]++;
adj[a].push_back(b);
}
queue<int> q;
for(int i = 1; i <= n; i++) if(deg[i] == 0) q.push(i);
while(!q.empty()){
int u = q.front(); q.pop();
topo.push_back(u);
for(auto v : adj[u]){
deg[v]--;
if(deg[v] == 0) q.push(v);
}
}
if(topo.size() != n) cout << -1;
else {
cout << n << '\n';
for(auto x : topo) cout << x << ' ' << 0 << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |