# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
983709 | Sandarach151 | Naboj (COCI22_naboj) | C++17 | 181 ms | 20204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> down[n];
vector<int> topsort;
int edge[n] = { 0 };
for(int i=0; i<m; i++){
int a, b;
cin >> a >> b;
a--;
b--;
down[a].push_back(b);
edge[b]++;
}
queue<int> noedge;
for(int i=0; i<n; i++){
if(edge[i]==0){
noedge.push(i);
}
}
while(!noedge.empty()){
int cur = noedge.front();
noedge.pop();
topsort.push_back(cur);
for(auto u : down[cur]){
edge[u]--;
if(edge[u]==0){
noedge.push(u);
}
}
}
// for(auto u : topsort){
// cout << u << ' ';
// }
if(topsort.size()!=n){
cout << -1 << '\n';
}
else{
cout << n-1 << '\n';
for(int i=n-2; i>=0; i--){
cout << topsort[i]+1 << ' ' << 1 << '\n';
}
}
return 0;
}
컴파일 시 표준 에러 (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... |