Submission #718514

# Submission time Handle Problem Language Result Execution time Memory
718514 2023-04-04T09:12:53 Z Augustyn Naboj (COCI22_naboj) C++17
110 / 110
183 ms 15160 KB
#include<iostream>
#include<vector>
#define gu getchar_unlocked
#define pf printf
using namespace std;
int sw()
{
    int ret=0,wcz=gu();
    while(wcz<'0'||wcz>'9')
        wcz=gu();
    while(wcz>='0'&&wcz<='9')
    {
        ret=ret*10+wcz-'0';
        wcz=gu();
    }
    return ret;
}
int n,m;
vector<int>*pol;
bool *juzodw,*terodw;
int *stp_wch,*odp,it;
bool dfs(int t)
{
    juzodw[t]=1;
    terodw[t]=1;
    for(int i:pol[t])
    {
        if(terodw[i]==1)
            return 1;
        if(juzodw[i]==0)
            if(dfs(i))
                return 1;
    }
    terodw[t]=0;
    odp[++it]=t;
    return 0;
}
int main()
{
    n=sw();m=sw();
    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;
        a=sw();b=sw();
        pol[b].push_back(a);
        stp_wch[a]++;
    }
    for(int i=1;i<=n;++i)
        if(stp_wch[i]==0)
            if(dfs(i))
            {
                pf("-1");
                return 0;
            }
    if(it!=n)
    {
        pf("-1");
        return 0;
    }
    pf("%d\n",n);
    for(int i=1;i<=n;++i)
        pf("%d 0\n",odp[i]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 12764 KB Output is correct
2 Correct 74 ms 12756 KB Output is correct
3 Correct 33 ms 6832 KB Output is correct
4 Correct 67 ms 12780 KB Output is correct
5 Correct 98 ms 12864 KB Output is correct
6 Correct 59 ms 12844 KB Output is correct
7 Correct 78 ms 12816 KB Output is correct
8 Correct 46 ms 10016 KB Output is correct
9 Correct 70 ms 12756 KB Output is correct
10 Correct 73 ms 12804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 80 ms 12764 KB Output is correct
16 Correct 74 ms 12756 KB Output is correct
17 Correct 33 ms 6832 KB Output is correct
18 Correct 67 ms 12780 KB Output is correct
19 Correct 98 ms 12864 KB Output is correct
20 Correct 59 ms 12844 KB Output is correct
21 Correct 78 ms 12816 KB Output is correct
22 Correct 46 ms 10016 KB Output is correct
23 Correct 70 ms 12756 KB Output is correct
24 Correct 73 ms 12804 KB Output is correct
25 Correct 49 ms 8780 KB Output is correct
26 Correct 74 ms 11216 KB Output is correct
27 Correct 67 ms 11692 KB Output is correct
28 Correct 75 ms 12136 KB Output is correct
29 Correct 42 ms 10788 KB Output is correct
30 Correct 84 ms 12236 KB Output is correct
31 Correct 8 ms 1748 KB Output is correct
32 Correct 64 ms 14876 KB Output is correct
33 Correct 115 ms 15080 KB Output is correct
34 Correct 90 ms 14808 KB Output is correct
35 Correct 127 ms 15060 KB Output is correct
36 Correct 77 ms 14836 KB Output is correct
37 Correct 138 ms 15044 KB Output is correct
38 Correct 102 ms 14860 KB Output is correct
39 Correct 121 ms 15100 KB Output is correct
40 Correct 101 ms 14984 KB Output is correct
41 Correct 116 ms 14916 KB Output is correct
42 Correct 183 ms 15112 KB Output is correct
43 Correct 93 ms 14904 KB Output is correct
44 Correct 127 ms 15160 KB Output is correct
45 Correct 78 ms 14880 KB Output is correct
46 Correct 122 ms 14944 KB Output is correct