Basic question, a total of N nodes, there are two nodes the connection between the two, so there are N * (N-1) / 2 edges. Each traversal time have to go through N edges, it can take a total of (N-1) / 2 times.
#include <iostream>
using namespace std;
int main()
{
int N;
while (cin >> N)
{
if (N == 0)
break;
cout << (N - 1) / 2 << endl;
}
return 0;
}
Keep up.