Submission #638807

#TimeUsernameProblemLanguageResultExecution timeMemory
638807mychecksedadNaboj (COCI22_naboj)C++17
110 / 110
261 ms42216 KiB
/* 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 (stderr)

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;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...