# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782211 | christinelynn | Naboj (COCI22_naboj) | C++17 | 339 ms | 16404 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>
using namespace std;
typedef long long ll;
ll n,m;
vector <ll> al[200005];
ll deg[200005];
int main(){
cin>>n>>m;
queue<ll> q;
for (int i=1;i<=m;i++){
ll a,b;
cin>>a>>b;
al[b].push_back(a);
deg[a]++;
}
vector <pair<ll,ll>> ans;
for (int i=1;i<=n;i++){
if (deg[i]==0) {
q.push(i);
ans.push_back({i,0});
}
}
while(!q.empty()){
ll u=q.front(); q.pop();
for (auto z:al[u]){
deg[z]--;
if (deg[z]==0){
ans.push_back({z,0});
q.push(z);
}
}
}
if (ans.size()!=n) cout<<-1;
else{
cout<<ans.size()<<endl;
for (auto z:ans){
cout<<z.first<<" "<<z.second<<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... |