Under construction

Still being built. Things may change

Buy and Delete

Time limit2sMemory limit1024 MB

Summary
Alice buys directed edges with total price at most c so that Bob needs as many acyclic deletion rounds as possible to remove every edge.
Level

Hard8 of 10

Topics
Graph, Game theory, Combinatorics
Solved
No attempts yet

Problem

Alice and Bob are playing a game on a directed graph GG. GG has nn vertices labeled 1,2,…,n1, 2, \dots, n. Initially, GG has no edges.

Alice first buys some directed edges from the shop and adds them to GG. After that, Bob deletes edges until GG has no edges. In each deletion round, Bob can delete a subset of edges SS from GG such that the graph that keeps only the edges in SS is acyclic. Alice can buy nothing, in which case the number of deletion rounds is 00.

The shop sells mm edges. Alice has cc dollars, so the total price of the edges she buys must not exceed cc. Alice wants to maximize the number of deletion rounds, and Bob wants to minimize it. Both play optimally. Predict the number of deletion rounds.

Input

The input contains only a single case.

The first line has three integers nn, mm, and cc (2≤n≤20002 \le n \le 2000, 1≤m≤50001 \le m \le 5000, 1≤c≤1091 \le c \le 10^9). Each of the next mm lines has three integers uiu_i, viv_i, and pip_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i, 1≤pi≤1000001 \le p_i \le 100000). Line ii describes a shop edge from uiu_i to viv_i that Alice can buy for pip_i dollars.

Output

Print a single integer, the number of deletion rounds.

Examples2

  1. Example 1

    Input
    3 2 4
    1 2 5
    2 3 6
    
    Expected output
    0
    
  2. Example 2

    Input
    3 3 3
    1 2 1
    2 3 1
    1 3 1
    
    Expected output
    1