Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Created January 9, 2017 18:10
Show Gist options
  • Save brun0xff/047a6803ca4c6af5882236950f04d70b to your computer and use it in GitHub Desktop.
Save brun0xff/047a6803ca4c6af5882236950f04d70b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#define maxV 10000
using namespace std;
int cnt = 0, lbl[maxV], movimentos, V, A;
int adj[100][100];
void pathR (int v) {
//cout << "lbl[v] " << lbl[v] << endl;
//cout << "cnt " << cnt << endl;
int w;
lbl[v] = cnt++;
//cout << "lbl[v] pos " << lbl[v] << endl;
//cout << "cnt pos " << cnt << endl;
//cout << "\n";
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(void) {
int orig,dest,N,casos,origem;
cin >> casos;
while (casos--) {
cin >> origem;
cin >> V; ///Vertices
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