# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
783682 | makanhulia | Naboj (COCI22_naboj) | C++17 | 388 ms | 14904 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>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define repp(i,n,k) for(int i=1;i<=n;i+=k)
#define repo(i,n,k) for(int i=0;i<n;i+=k)
#define pb push_back
using namespace std;
ll arr[200005];
vector<ll> adj[200005];
vector<ll> ans;
int main(){
ll m,n;cin>>m>>n;
queue<ll> q;
for(int i=1;i<=n;i++){
ll a,b;cin>>a>>b;
adj[a].push_back(b);
arr[b]++;
}
repp(i,n,1){
if(arr[i]==0) q.push(i);
}
while(!q.empty()){
ll cur=q.front();
ans.pb(cur);
q.pop();
for(ll nx:adj[cur]){
arr[nx]--;
if(arr[nx]==0) q.push(nx);
}
}
if(ans.size()!=m) cout<<"-1";
else {
cout<<ans.size()<<endl;
for(ll nx:ans){
cout<<nx<<" 0"<<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... |