# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718504 | Augustyn | Naboj (COCI22_naboj) | C++17 | 296 ms | 21328 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<iostream>
#include<vector>
using namespace std;
int n,m;
vector<int>*pol;
bool *juzodw,*terodw;
int *stp_wch,*odp,iter;
bool dfs(int ter)
{
juzodw[ter]=1;
terodw[ter]=1;
for(auto i:pol[ter])
{
if(terodw[i]==1)
return 1;
if(juzodw[i]==0)
if(dfs(i))
return 1;
}
terodw[ter]=0;
odp[++iter]=ter;
return 0;
}
int main()
{
scanf("%d%d",&n,&m);
pol=new vector<int>[n+1];
juzodw=new bool[n+1];
terodw=new bool[n+1];
odp=new int[n+1];
stp_wch=new int[n+1];
while(m)
{
--m;
int a,b;
scanf("%d%d",&a,&b);
pol[b].push_back(a);
stp_wch[a]++;
}
for(int i=1;i<=n;++i)
if(stp_wch[i]==0)
if(dfs(i))
{
printf("-1");
return 0;
}
if(iter!=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... |