Submission #932903

# Submission time Handle Problem Language Result Execution time Memory
932903 2024-02-24T12:51:08 Z a_l_i_r_e_z_a Naboj (COCI22_naboj) C++17
110 / 110
162 ms 21252 KB
// In the name of God
// Hope is last to die

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 2e5 + 5;
const int inf = 1e9 + 7;
int n, m, mark[maxn];
vector<int> adj[maxn], topol;

void dfs(int v){
    mark[v] = 1;
    for(auto u: adj[v]){
        if(!mark[u]) dfs(u);
        else if(mark[u] == 1){
            cout << -1 << '\n';
            exit(0);
        }
    }
    topol.pb(v);
    mark[v] = 2;
}

void topolo(){
    for(int i = 1; i <= n; i++) if(!mark[i]) dfs(i);
    reverse(all(topol));
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        adj[v].pb(u);
    }
    topolo();
    cout << n << '\n';
    for(int i = 0; i < n; i++){
        cout << topol[i] << ' ' << 1 << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5156 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 15072 KB Output is correct
2 Correct 71 ms 15048 KB Output is correct
3 Correct 32 ms 10192 KB Output is correct
4 Correct 66 ms 15056 KB Output is correct
5 Correct 73 ms 15156 KB Output is correct
6 Correct 65 ms 15240 KB Output is correct
7 Correct 68 ms 15040 KB Output is correct
8 Correct 50 ms 13000 KB Output is correct
9 Correct 72 ms 15300 KB Output is correct
10 Correct 83 ms 15096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5156 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4968 KB Output is correct
15 Correct 69 ms 15072 KB Output is correct
16 Correct 71 ms 15048 KB Output is correct
17 Correct 32 ms 10192 KB Output is correct
18 Correct 66 ms 15056 KB Output is correct
19 Correct 73 ms 15156 KB Output is correct
20 Correct 65 ms 15240 KB Output is correct
21 Correct 68 ms 15040 KB Output is correct
22 Correct 50 ms 13000 KB Output is correct
23 Correct 72 ms 15300 KB Output is correct
24 Correct 83 ms 15096 KB Output is correct
25 Correct 72 ms 14932 KB Output is correct
26 Correct 68 ms 15080 KB Output is correct
27 Correct 88 ms 15700 KB Output is correct
28 Correct 96 ms 17748 KB Output is correct
29 Correct 56 ms 13392 KB Output is correct
30 Correct 99 ms 17644 KB Output is correct
31 Correct 14 ms 6868 KB Output is correct
32 Correct 70 ms 17608 KB Output is correct
33 Correct 147 ms 20580 KB Output is correct
34 Correct 82 ms 17864 KB Output is correct
35 Correct 115 ms 20684 KB Output is correct
36 Correct 77 ms 17348 KB Output is correct
37 Correct 129 ms 19916 KB Output is correct
38 Correct 102 ms 18892 KB Output is correct
39 Correct 124 ms 20396 KB Output is correct
40 Correct 133 ms 19568 KB Output is correct
41 Correct 101 ms 19512 KB Output is correct
42 Correct 152 ms 20956 KB Output is correct
43 Correct 82 ms 18116 KB Output is correct
44 Correct 162 ms 21252 KB Output is correct
45 Correct 77 ms 17652 KB Output is correct
46 Correct 114 ms 19420 KB Output is correct