Edges and Divisors
시간 제한1초메모리 제한2048 MB
길이 1, 2, ...의 경로를 골라 i번째 경로의 간선 가중치 합이 i+1의 배수가 되게 하면서 가중 평균 경로 길이를 최대화한다.
문제
We play a game on a directed acyclic graph . We start at vertex . The rules of the game are as follows:
- The game consists of rounds numbered from .
- In the -th round, the player selects a path starting from and containing at least one edge such that the sum of the weights of all edges belonging to this path is an exact multiple of . If the player cannot select such a path, the player has failed, and will not score any points. Otherwise, the round ends successfully, and the endpoint of is recorded as .
- After a successful round, the player can either end the game or continue with the next round. If the player chooses to end the game, the selected paths are called doubling paths, and the score is calculated.
If the player has not failed, then when ending the game, for the selected doubling paths , the score of the game is defined as , where represents the number of edges in path , and is the weight given in the input. Clearly, as the graph is acyclic, at most paths can be selected, so the input only provides the weights .
Given the graph and the starting vertex, calculate the maximum achievable score in the game.
입력
The first line of input contains three integers, , , and : the number of vertices, the number of edges, and the index of the starting vertex (; ; ).
The second line contains integers : the weights used to calculate the score ().
Each of the next lines contains three integers, , , and , describing a directed edge from to with weight (; ; ). It is guaranteed that the graph is acyclic, the graph is connected if we treat edges as undirected, and there are no multiple edges.
출력
Output a single line containing two integers separated by a space.
If at least one path can be selected, there exists an optimal selection scheme that maximizes the score, and the optimal score can be represented as where and are coprime integers and . In this case, output and . Otherwise (if it is impossible to select any paths), output "-1~-1".
힌트
The selected doubling paths are and .