Ejemplo n.º 1
0
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	int n;
	int m;
	scanf("%d%d", &n, &m);

	TGraph g;
	g.resize(n);

	for (int i = 0; i < m; ++i) {
		int begin;
		int end;
		scanf("%d%d", &begin, &end);
		--begin;
		--end;
		g[begin].push_back(end);
		g[end].push_back(begin);
	}

	int s;
	int f;
	int r;
	scanf("%d%d%d", &s, &f, &r);
	--s;
	--f;
	--r;

	TLine sDist;
	DFS(g, s, &sDist);
	TLine rDist;
	DFS(g, r, &rDist);

	TLine cache(n, -1);
	cache[s] = rDist[s];

	TrackMaxDist(g, sDist, rDist, f, &cache);

	printf("%d\n", cache[f]);

	return 0;
}