Submission #784351

#TimeUsernameProblemLanguageResultExecution timeMemory
784351andecaandeciNaboj (COCI22_naboj)C++17
110 / 110
237 ms21028 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define TC int t; cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
//*AC BERSAMA ALLAH  FORTIS FORTUNA ADIUVAT

const ll sez = 2e5 + 5;
ll n,m; 
vector<pair<ll,ll> > arr;
vector<int> adj[sez], deg(sez,0), topo;
vector<bool> vis(sez,0);

void dfs(int u){
    if(vis[u]) return;
    vis[u]=1;
    topo.pb(u);
    for(auto i : adj[u]){
        deg[i]--;
        if(deg[i]==0) dfs(i);
    }
}

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

    cin>>n>>m;

    for(int i=1;i<=m;i++){
        int u,v; cin>>u>>v;
        adj[v].pb(u);
        deg[u]++;
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==0 && !vis[i]){
            dfs(i);
        }
    }
    if(topo.size()!=n) cout<<"-1\n";
    else{
        cout<<topo.size()<<'\n';
        for(int i : topo){
            cout<<i<<' '<<1<<'\n';
        }
    }

    return 0;
}

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:43:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   43 |     if(topo.size()!=n) cout<<"-1\n";
      |        ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...