Under construction

Still being built. Things may change

Kimbap Heaven and Road Hell

Time limit2sMemory limit1024 MB

Summary
Given roads of 2, 3, or 6 minutes, determine whether a walk from district 1 can reach district N at exactly K minutes.
Level

Medium7 of 10

Topics
Graph, Shortest path, Number theory
Solved
No attempts yet

Problem

Sejin lives in a town with NN districts and MM roads connecting them. The districts are numbered 1 to NN. The roads come in three colors: red, yellow, and blue.

Sejin loves kimbap so much that instead of going to Kimbap Heaven himself, he built a delivery robot that can order food for him. The robot never stops moving. It takes exactly 2, 3, and 6 minutes to cross a red, yellow, or blue road, respectively.

Sejin just called Kimbap Heaven and said he will come pick up the food in exactly KK minutes. He plans to start the robot from his location right now. Given the town layout, Sejin's location, and the kimbap shop's location, determine whether the robot can follow a route that reaches the shop at exactly minute KK.

The robot may revisit districts or travel the same road more than once to make the time work out. It may also pass through the district with the shop before arriving. You only need to check whether the robot can be at the shop's location exactly KK minutes after it starts.

Input

The first line contains NN, MM, and KK, separated by spaces. (2≤N≤100 000;(2 \le N \le 100\,000; N−1≤M≤min⁡(100 000,3N(N−1)/2);N - 1 \le M \le \min(100\,000, 3N(N-1)/2); 1≤K≤109)1 \le K \le 10^9)

Each of the next MM lines contains ii, jj, and ww, separated by spaces. This means there is a road between districts ii and jj that takes ww minutes to cross. (1≤i<j≤N;(1 \le i < j \le N; w∈{2,3,6})w \in \{2, 3, 6\})

All roads can be traveled in both directions. Two roads of the same color are never given between the same pair of districts. The roads are given so that every district can be reached from district 1.

The robot always starts at district 1, and the kimbap shop is always at district NN.

Output

Print YES if the robot can reach the shop at exactly minute KK, and NO if it cannot.

Examples2

  1. Example 1

    Input
    5 5 31
    1 2 6
    2 3 6
    3 4 2
    3 4 3
    2 5 6
    
    Expected output
    NO
    
  2. Example 2

    Input
    5 5 29
    1 2 6
    2 3 6
    3 4 2
    3 4 3
    2 5 6
    
    Expected output
    YES