Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Created December 22, 2016 22:53
Show Gist options
  • Save brun0xff/9ef667c534f2b7f09f4659fae5e86331 to your computer and use it in GitHub Desktop.
Save brun0xff/9ef667c534f2b7f09f4659fae5e86331 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#define maxV 10000
using namespace std;
int cnt, lbl[maxV], movimentos, cont=0, V, A,G;
int adj[100][100];
void pathR (int v) {
int w;
lbl[v] = cnt++;
for (w = 0; w < V; w++) {
if (adj[v][w] == 1) {
if (lbl[w] == -1) {
movimentos++;
pathR(w);
}
}
}
}
void DIGRAPHpath (int origem) {
int v;
for (v = 0; v < V; v++) {
lbl[v] = -1;
}
pathR (origem);
}
int main() {
int orig,dest,N,casos,origem;
cin >> casos;
while (casos--) {
cin >> origem;
cin >> V;
for (int i=0; i<V; i++) {
for (int j=0; j<V; j++) {
adj[i][j]=0;
}
}
movimentos=0;
cin >> A;
for (int i=0; i<A; i++) {
cin >> orig >> dest;
adj[orig][dest]=1;
adj[dest][orig]=1;
}
DIGRAPHpath(origem);
cout << movimentos*2 << endl;
}
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment