Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
11080 WIP
//g++ 5.4.0 #include <iostream> #include <vector> using namespace std; vector<int> lista[200]; bool visit[200]={false}; int nodos; int cont; int dfs(int nodo){ visit[nodo]=true; for(auto c: lista[nodo]) if(!visit[c]) dfs(c); } int main() { int T, vertices, a, b; cin>>T; while(T--){ for(int i=0;i<) cont=0; cin>>nodos; cin>>vertices; for(int i=0; i<vertices; i++){ cin>>a; cin>>b; lista[a].push_back(b); //lista[b].push_back(a); } /*for(int i=0; i<nodos; i++){ cout<<i<<":"; for(auto prueba: lista[i]){ cout<<prueba<<" "; }cout<<"\n"; }*/ for(int i=0; i<nodos; i++){ if(!visit[i]){ dfs(i); cont++; } } if(cont==1) cout<<"-1\n"; else cout<<cont<<"\n"; } }
run
|
edit
|
history
|
help
0
segmentedSieveD
Eratosfen final
Kolokwium_2011_z12
Graph Theory 2
Grundy Number
Test 5(2020)
Left view of a tree
bitmap with pairs
Queue with Limited Size of Arrays
scanf error