답안 #718510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718510 2023-04-04T09:09:56 Z Augustyn Naboj (COCI22_naboj) C++17
110 / 110
152 ms 15128 KB
#include<iostream>
#include<vector>
using namespace std;
int sw()
{
    int ret=0,wcz=getchar_unlocked();
    while(wcz<'0'||wcz>'9')
        wcz=getchar_unlocked();
    while(wcz>='0'&&wcz<='9')
    {
        ret=ret*10+wcz-'0';
        wcz=getchar_unlocked();
    }
    return ret;
}
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()
{
    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))
            {
                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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 12844 KB Output is correct
2 Correct 93 ms 12864 KB Output is correct
3 Correct 25 ms 6880 KB Output is correct
4 Correct 73 ms 12832 KB Output is correct
5 Correct 82 ms 12724 KB Output is correct
6 Correct 71 ms 12832 KB Output is correct
7 Correct 69 ms 12792 KB Output is correct
8 Correct 48 ms 10028 KB Output is correct
9 Correct 69 ms 12788 KB Output is correct
10 Correct 100 ms 12740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 68 ms 12844 KB Output is correct
16 Correct 93 ms 12864 KB Output is correct
17 Correct 25 ms 6880 KB Output is correct
18 Correct 73 ms 12832 KB Output is correct
19 Correct 82 ms 12724 KB Output is correct
20 Correct 71 ms 12832 KB Output is correct
21 Correct 69 ms 12792 KB Output is correct
22 Correct 48 ms 10028 KB Output is correct
23 Correct 69 ms 12788 KB Output is correct
24 Correct 100 ms 12740 KB Output is correct
25 Correct 60 ms 8732 KB Output is correct
26 Correct 59 ms 11204 KB Output is correct
27 Correct 78 ms 11704 KB Output is correct
28 Correct 124 ms 12104 KB Output is correct
29 Correct 49 ms 10828 KB Output is correct
30 Correct 77 ms 12152 KB Output is correct
31 Correct 9 ms 1720 KB Output is correct
32 Correct 86 ms 14860 KB Output is correct
33 Correct 134 ms 15052 KB Output is correct
34 Correct 90 ms 14900 KB Output is correct
35 Correct 136 ms 15096 KB Output is correct
36 Correct 73 ms 14796 KB Output is correct
37 Correct 119 ms 14932 KB Output is correct
38 Correct 112 ms 14840 KB Output is correct
39 Correct 135 ms 15040 KB Output is correct
40 Correct 121 ms 14992 KB Output is correct
41 Correct 119 ms 14952 KB Output is correct
42 Correct 152 ms 15128 KB Output is correct
43 Correct 94 ms 14900 KB Output is correct
44 Correct 143 ms 15112 KB Output is correct
45 Correct 86 ms 14872 KB Output is correct
46 Correct 143 ms 14896 KB Output is correct