Buy and Delete

시간 제한2초메모리 제한1024 MB

요약
앨리스가 예산 c 안에서 방향 간선을 사서 그래프에 넣으면, 밥이 비순환 부분집합을 한 라운드씩 지워 그래프를 비우는데, 두 사람이 최적으로 둘 때 필요한 라운드 수를 구한다.
난이도

어려움10점 중 8점

유형
게임 이론, 그래프, 동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

Alice and Bob are playing a game on a directed graph GG. There are nn vertices in GG, labeled by 1,2,…,n1,2,\dots,n. Initially, there are no edges in GG. Alice will first buy some direct edges from the shop and then add them into GG. After that, Bob needs to delete edges until there are no edges in GG. In a deletion round, Bob can delete a subset of edges SS from GG, such that when only keeping edges in SS, the graph is acyclic. Note that Alice can buy nothing, and in such a case the number of deletion rounds is 00.

There are mm edges in the shop. Alice has cc dollars, so the total price of edges she will buy should not exceed cc. Alice wants to maximize the number of deletion rounds while Bob wants to minimize it. Both Alice and Bob will play optimally. Please write a program to predict the number of deletion rounds.

입력

The input contains only a single case.

The first line of the input contains three integers n,mn,m and cc (2≤n≤2,0002 \leq n\leq 2\\,000, 1≤m≤5,0001\leq m \leq 5\\,000, 1≤c≤1091\leq c\leq 10^9), denoting the number of vertices in GG, the number of edges in the shop, and how many dollars Alice has.

In the next mm lines, the ii-th line (1≤i≤m)(1 \le i \le m) contains three integers u_i,v_iu\_i,v\_i and p_ip\_i (1≤u_i,v_i≤n1\leq u\_i,v\_i\leq n, u_i≠v_iu\_i\neq v\_i, 1≤p_i≤100,0001\leq p\_i\leq 100\\,000), denoting a directed edge in the shop. Alice can pay p_ip\_i dollars to buy it, and add an edge from vertex u_iu\_i to vertex v_iv\_i in GG.

출력

Print a single line containing an integer, denoting the number of deletion rounds.

예제2

  1. 예제 1

    입력
    3 2 4
    1 2 5
    2 3 6
    
    예상 출력
    0
    
  2. 예제 2

    입력
    3 3 3
    1 2 1
    2 3 1
    1 3 1
    
    예상 출력
    1