Buy and Delete
Time limit2sMemory limit1024 MB
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 . has vertices labeled . Initially, has no edges.
Alice first buys some directed edges from the shop and adds them to . After that, Bob deletes edges until has no edges. In each deletion round, Bob can delete a subset of edges from such that the graph that keeps only the edges in is acyclic. Alice can buy nothing, in which case the number of deletion rounds is .
The shop sells edges. Alice has dollars, so the total price of the edges she buys must not exceed . 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 , , and (, , ). Each of the next lines has three integers , , and (, , ). Line describes a shop edge from to that Alice can buy for dollars.
Output
Print a single integer, the number of deletion rounds.