All problems

Problem 430

City with the Fewest Reachable Neighbours

Medium · 20 pts · Graph, Shortest Path, Floyd-Warshall

Problem

There are N cities labelled 1 to N, connected by two-way roads with lengths. For each city, count how many other cities can be reached from it by a route whose total length is at most a threshold T. Print the city with the smallest such count; if several cities tie, print the one with the largest label. With N up to 100, running Floyd-Warshall to get all shortest distances is simple and fast enough.

Input

First line: N, M and T. Next M lines: a road u v w.

Output

Print the chosen city's label.

Constraints

2 <= N <= 100; 0 <= M <= N(N-1)/2; 1 <= w, T <= 10000

Example input

4 4 4
1 2 3
2 3 1
2 4 4
3 4 1

Example output

4

Explanation

With threshold 4, cities 1 and 4 can each reach 2 other cities, while cities 2 and 3 reach 3. Cities 1 and 4 tie with the fewest, and 4 has the larger label.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Minimum Semesters to Finish Courses Next: Minimum Edge Reversals