Submission #718528

# Submission time Handle Problem Language Result Execution time Memory
718528 2023-04-04T09:31:26 Z Augustyn Naboj (COCI22_naboj) C++17
110 / 110
267 ms 15180 KB
#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

naboj.cpp: In function 'int main()':
naboj.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
naboj.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4976 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 12752 KB Output is correct
2 Correct 138 ms 12756 KB Output is correct
3 Correct 59 ms 9216 KB Output is correct
4 Correct 150 ms 12808 KB Output is correct
5 Correct 141 ms 12776 KB Output is correct
6 Correct 136 ms 12760 KB Output is correct
7 Correct 140 ms 12792 KB Output is correct
8 Correct 77 ms 10988 KB Output is correct
9 Correct 144 ms 12704 KB Output is correct
10 Correct 118 ms 12840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4924 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4976 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 126 ms 12752 KB Output is correct
16 Correct 138 ms 12756 KB Output is correct
17 Correct 59 ms 9216 KB Output is correct
18 Correct 150 ms 12808 KB Output is correct
19 Correct 141 ms 12776 KB Output is correct
20 Correct 136 ms 12760 KB Output is correct
21 Correct 140 ms 12792 KB Output is correct
22 Correct 77 ms 10988 KB Output is correct
23 Correct 144 ms 12704 KB Output is correct
24 Correct 118 ms 12840 KB Output is correct
25 Correct 162 ms 10316 KB Output is correct
26 Correct 139 ms 11212 KB Output is correct
27 Correct 130 ms 11576 KB Output is correct
28 Correct 187 ms 12220 KB Output is correct
29 Correct 87 ms 10792 KB Output is correct
30 Correct 181 ms 12152 KB Output is correct
31 Correct 25 ms 5972 KB Output is correct
32 Correct 142 ms 14968 KB Output is correct
33 Correct 221 ms 15180 KB Output is correct
34 Correct 158 ms 14924 KB Output is correct
35 Correct 224 ms 15020 KB Output is correct
36 Correct 119 ms 14904 KB Output is correct
37 Correct 267 ms 14916 KB Output is correct
38 Correct 173 ms 14820 KB Output is correct
39 Correct 216 ms 15068 KB Output is correct
40 Correct 210 ms 14924 KB Output is correct
41 Correct 181 ms 14860 KB Output is correct
42 Correct 243 ms 15152 KB Output is correct
43 Correct 158 ms 14976 KB Output is correct
44 Correct 245 ms 15144 KB Output is correct
45 Correct 119 ms 14796 KB Output is correct
46 Correct 190 ms 15052 KB Output is correct