Submission #704871

# Submission time Handle Problem Language Result Execution time Memory
704871 2023-03-03T06:12:44 Z browntoad Naboj (COCI22_naboj) C++14
110 / 110
478 ms 18520 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i=(n)-1; i>=0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

const ll maxn = 2e5+5;

int n, m;
vector<int> graph[maxn];
vector<int> in(maxn);
vector<bool> occ(maxn);
void inp(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n>>m;
    REP(i, m){
        int u, v; cin>>u>>v;
        graph[u].pb(v);
        in[v]++;
    }
}
vector<pii> res;
void solve(){
    queue<int> qu;
    REP1(i, n){
        if (in[i] == 0) qu.push(i);
    }
    vector<int> topo;
    while(qu.size()){
        int x=qu.front(); qu.pop();
        occ[x]=1;
        topo.pb(x);
        REP(i, SZ(graph[x])){
            in[graph[x][i]]--;
            if (in[graph[x][i]] == 0){
                qu.push(graph[x][i]);
            }
        }
    }
    bool gg=0;
    REP1(i, n){
        if (occ[i] == 0){
            gg=1;
            break;
        }
    }
    if (gg) {
        if (m==n-1) assert(0);
        cout<<-1<<endl;
        return;
    }
    assert(SZ(topo)==n);
    cout<<n<<endl;
    REP(i, n){
        cout<<topo[i]<<' '<<0<<endl;
    }


}
signed main(){
    inp();
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6612 KB Output is correct
2 Correct 3 ms 6612 KB Output is correct
3 Correct 3 ms 6596 KB Output is correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 3 ms 6612 KB Output is correct
6 Correct 3 ms 6612 KB Output is correct
7 Correct 3 ms 6612 KB Output is correct
8 Correct 3 ms 6612 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 3 ms 6620 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 3 ms 6612 KB Output is correct
13 Correct 3 ms 6612 KB Output is correct
14 Correct 3 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 338 ms 15008 KB Output is correct
2 Correct 333 ms 14908 KB Output is correct
3 Correct 163 ms 10952 KB Output is correct
4 Correct 328 ms 14980 KB Output is correct
5 Correct 326 ms 15004 KB Output is correct
6 Correct 420 ms 14896 KB Output is correct
7 Correct 334 ms 14964 KB Output is correct
8 Correct 258 ms 13152 KB Output is correct
9 Correct 329 ms 15032 KB Output is correct
10 Correct 329 ms 14912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6612 KB Output is correct
2 Correct 3 ms 6612 KB Output is correct
3 Correct 3 ms 6596 KB Output is correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 3 ms 6612 KB Output is correct
6 Correct 3 ms 6612 KB Output is correct
7 Correct 3 ms 6612 KB Output is correct
8 Correct 3 ms 6612 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 3 ms 6620 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 3 ms 6612 KB Output is correct
13 Correct 3 ms 6612 KB Output is correct
14 Correct 3 ms 6612 KB Output is correct
15 Correct 338 ms 15008 KB Output is correct
16 Correct 333 ms 14908 KB Output is correct
17 Correct 163 ms 10952 KB Output is correct
18 Correct 328 ms 14980 KB Output is correct
19 Correct 326 ms 15004 KB Output is correct
20 Correct 420 ms 14896 KB Output is correct
21 Correct 334 ms 14964 KB Output is correct
22 Correct 258 ms 13152 KB Output is correct
23 Correct 329 ms 15032 KB Output is correct
24 Correct 329 ms 14912 KB Output is correct
25 Correct 153 ms 14288 KB Output is correct
26 Correct 124 ms 14704 KB Output is correct
27 Correct 139 ms 15060 KB Output is correct
28 Correct 201 ms 16320 KB Output is correct
29 Correct 113 ms 15184 KB Output is correct
30 Correct 177 ms 16032 KB Output is correct
31 Correct 22 ms 8652 KB Output is correct
32 Correct 356 ms 15064 KB Output is correct
33 Correct 448 ms 18220 KB Output is correct
34 Correct 362 ms 15376 KB Output is correct
35 Correct 466 ms 18140 KB Output is correct
36 Correct 353 ms 14628 KB Output is correct
37 Correct 442 ms 17340 KB Output is correct
38 Correct 400 ms 16304 KB Output is correct
39 Correct 443 ms 18008 KB Output is correct
40 Correct 419 ms 17056 KB Output is correct
41 Correct 433 ms 16812 KB Output is correct
42 Correct 478 ms 18448 KB Output is correct
43 Correct 384 ms 15528 KB Output is correct
44 Correct 460 ms 18520 KB Output is correct
45 Correct 360 ms 15004 KB Output is correct
46 Correct 416 ms 16908 KB Output is correct