#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define all(x) x.begin(),x.end()
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
vector<int> in(n,0);
vector<bool> visited(n,false);
vector<int> adj[n],adjr[n];
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;
b--;
in[a]++;
adj[b].push_back(a);
}
queue<int> q;
for(int i=0;i<n;i++){
if(in[i]==0) q.push(i);
}
vector<pair<int,int>> ans;
while(!q.empty()){
int v=q.front();
q.pop();
visited[v]=true;
ans.push_back({v,0});
for(auto u:adj[v]){
if(visited[u]){
cout<<-1;
return 0;
}
in[u]--;
if(in[u]==0){
q.push(u);
}
}
}
reverse(all(ans));
for(auto v:ans){
cout<<v.f+1<<' '<<v.s<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Integer parameter [name=c] equals to 0, violates the range [1, 9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
19376 KB |
Integer parameter [name=c] equals to 0, violates the range [1, 200000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Integer parameter [name=c] equals to 0, violates the range [1, 9] |
2 |
Halted |
0 ms |
0 KB |
- |