# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718528 | Augustyn | Naboj (COCI22_naboj) | C++17 | 267 ms | 15180 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 x 200001
int n,m,sw[x],odp[x],it;
vector<int>p[x];
bool jo[x],to[x];
bool dfs(int t)
{
jo[t]=to[t]=1;
for(int i:p[t])
{
if(to[i]==1)
return 1;
if(jo[i]==0)
if(dfs(i))
return 1;
}
to[t]=0;
odp[++it]=t;
return 0;
}
int main()
{
scanf("%d%d",&n,&m);
while(m)
{
--m;
int a,b;
scanf("%d%d",&a,&b);
p[b].push_back(a);
sw[a]++;
}
for(int i=1;i<=n;++i)
if(sw[i]==0)
if(dfs(i))
{
printf("-1");
return 0;
}
if(it!=n)
{
printf("-1");
return 0;
}
printf("%d\n",n);
for(int i=1;i<=n;++i)
printf("%d 0\n",odp[i]);
return 0;
}
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... |