답안 #638807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638807 2022-09-07T14:13:58 Z mychecksedad Naboj (COCI22_naboj) C++17
110 / 110
261 ms 42216 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;



int n, m, in[N];
vector<int> g[N], path, vis;
bool ok = 1;
void dfs(int v){
    vis[v] = 1;
    for(int u: g[v]){
        if(vis[u] == 1){
            ok = 0;
        }else if(!vis[u]) dfs(u);
    }
    path.pb(v);
    vis[v] = 2;
}


void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) in[i] = 0;
    for(;m--;){
        int u, v; cin >> u >> v;
        g[v].pb(u);
    }
    vis.resize(n+1);
    for(int i = 1; i <= n; ++i) if(vis[i] == 0) dfs(i);


    if(!ok){
        cout << -1;
        return;
    }

    reverse(all(path));

    vector<pair<int, int>> ans;
    for(int i = 1; i < path.size(); ++i){
        ans.pb({path[i], 1});
    }

    cout << ans.size() << '\n';
    for(auto k: ans) cout << k.first << ' ' << k.second << '\n';
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

naboj.cpp: In function 'void solve()':
naboj.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 1; i < path.size(); ++i){
      |                    ~~^~~~~~~~~~~~~
naboj.cpp: In function 'int main()':
naboj.cpp:65:16: warning: unused variable 'aa' [-Wunused-variable]
   65 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23812 KB Output is correct
2 Correct 14 ms 23816 KB Output is correct
3 Correct 13 ms 23820 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 14 ms 23776 KB Output is correct
7 Correct 12 ms 23704 KB Output is correct
8 Correct 13 ms 23784 KB Output is correct
9 Correct 14 ms 23776 KB Output is correct
10 Correct 12 ms 23768 KB Output is correct
11 Correct 15 ms 23816 KB Output is correct
12 Correct 17 ms 23704 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 36208 KB Output is correct
2 Correct 121 ms 36208 KB Output is correct
3 Correct 78 ms 30324 KB Output is correct
4 Correct 111 ms 36292 KB Output is correct
5 Correct 121 ms 36204 KB Output is correct
6 Correct 114 ms 36284 KB Output is correct
7 Correct 111 ms 36220 KB Output is correct
8 Correct 114 ms 33484 KB Output is correct
9 Correct 117 ms 36276 KB Output is correct
10 Correct 152 ms 36236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23812 KB Output is correct
2 Correct 14 ms 23816 KB Output is correct
3 Correct 13 ms 23820 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 14 ms 23776 KB Output is correct
7 Correct 12 ms 23704 KB Output is correct
8 Correct 13 ms 23784 KB Output is correct
9 Correct 14 ms 23776 KB Output is correct
10 Correct 12 ms 23768 KB Output is correct
11 Correct 15 ms 23816 KB Output is correct
12 Correct 17 ms 23704 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 119 ms 36208 KB Output is correct
16 Correct 121 ms 36208 KB Output is correct
17 Correct 78 ms 30324 KB Output is correct
18 Correct 111 ms 36292 KB Output is correct
19 Correct 121 ms 36204 KB Output is correct
20 Correct 114 ms 36284 KB Output is correct
21 Correct 111 ms 36220 KB Output is correct
22 Correct 114 ms 33484 KB Output is correct
23 Correct 117 ms 36276 KB Output is correct
24 Correct 152 ms 36236 KB Output is correct
25 Correct 139 ms 38440 KB Output is correct
26 Correct 120 ms 36188 KB Output is correct
27 Correct 143 ms 38624 KB Output is correct
28 Correct 191 ms 41716 KB Output is correct
29 Correct 114 ms 34308 KB Output is correct
30 Correct 185 ms 41420 KB Output is correct
31 Correct 41 ms 26444 KB Output is correct
32 Correct 131 ms 38636 KB Output is correct
33 Correct 261 ms 41672 KB Output is correct
34 Correct 128 ms 38872 KB Output is correct
35 Correct 229 ms 41704 KB Output is correct
36 Correct 114 ms 38524 KB Output is correct
37 Correct 185 ms 41000 KB Output is correct
38 Correct 172 ms 40044 KB Output is correct
39 Correct 222 ms 41664 KB Output is correct
40 Correct 171 ms 40584 KB Output is correct
41 Correct 187 ms 40572 KB Output is correct
42 Correct 236 ms 42216 KB Output is correct
43 Correct 138 ms 39224 KB Output is correct
44 Correct 246 ms 42172 KB Output is correct
45 Correct 142 ms 38892 KB Output is correct
46 Correct 190 ms 40612 KB Output is correct