# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
783747 | christinelynn | Naboj (COCI22_naboj) | C++17 | 445 ms | 18500 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
#define pii pair<int,int>
#define supercepat ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
using namespace std;
int tc,ans=0,n,m;
int in1,in2;
vector<int> adj[200005];
bool vis[200005];
int point[200005];
vector<int> topo;
void dfs(int x){
if(vis[x]) return;
vis[x]=1;
topo.pb(x);
for(auto i : adj[x]){
point[i]--;
if(point[i]==0){
dfs(i);
}
}
}
main(){
supercepat;
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>in1>>in2;
adj[in2].pb(in1);
point[in1]++;
}
for(int i=1;i<=n;i++){
if(point[i]==0&&!vis[i]){
dfs(i);
}
}
if(topo.size()!=n){
cout<<-1<<endl;
}
else{
cout<<topo.size()<<endl;
for(auto i : topo){
cout<<i<<" "<<1<<endl;
}
}
}
Compilation message (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... |