# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782203 | andecaandeci | Naboj (COCI22_naboj) | C++17 | 175 ms | 17768 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;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long, long long>
long long n,m,deg[200005];
vector<long long> vec[200005];
queue<long long> q;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
long long tc,i,j;
cin>>n>>m;
for(i=1;i<=m;i++)
{
long long u,v;
cin>>u>>v;
deg[v]++;
vec[u].push_back(v);
}
vector<long long> ans;
for(i=1;i<=n;i++)
{
if(deg[i] == 0)
{
q.push(i);
ans.push_back(i);
}
}
while(!q.empty())
{
long long node = q.front();
q.pop();
for(auto it : vec[node])
{
deg[it]--;
if(deg[it] == 0)
{
q.push(it);
ans.push_back(it);
}
}
}
for(i=1;i<=n;i++)
{
if(deg[i] > 0)
{
break;
}
}
if(i <= n)
{
cout<<-1<<'\n';
}
else
{
cout<<ans.size()<<'\n';
for(auto it : ans)
{
cout<<it<<" 0\n";
}
}
}
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... |