My Lime Orange Tree
Time limit3sMemory limit1024 MB
Given a tree whose edges hold lime orange counts, decide for each starting root whether the first player wins the piece-moving game.
- Level
Medium7 of 10
- Topics
- Tree, Game theory, Dynamic programming
- Solved
- No attempts yet
Problem
Mingming, the lime orange tree that Zeze cherishes, is a connected graph with vertices and edges. Edge of Mingming has lime oranges on it. Zeze and Portuga want to play a game on Mingming. On the first turn, Zeze places a piece on vertex , the root of Mingming. On each turn, the two players repeat the following steps.
- Choose any edge adjacent to the vertex where the piece is.
- Pick at least one lime orange from the chosen edge.
- Move the piece to the vertex on the other end of the chosen edge.
When a player cannot continue, that is, when no edge adjacent to the piece's vertex has a lime orange left to pick, that player loses the game. For , write a program that prints "Zeze" if Zeze wins and "Portuga" if Portuga wins, without quotes.
Input
The first line contains , the number of vertices of Mingming.
From the second line to line , each of the lines gives , , and in the form , where and are the endpoints of edge and is the number of lime oranges on it.
Output
For , print "Zeze" if Zeze wins or "Portuga" if Portuga wins, without quotes, on separate lines.