Edges and Divisors

시간 제한1초메모리 제한2048 MB

요약
길이 1, 2, ...의 경로를 골라 i번째 경로의 간선 가중치 합이 i+1의 배수가 되게 하면서 가중 평균 경로 길이를 최대화한다.
난이도

어려움10점 중 9점

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

문제

We play a game on a directed acyclic graph G=(V,E)G = (V, E). We start at vertex s_1∈Vs\_1 \in V. The rules of the game are as follows:

  • The game consists of rounds numbered from 11.
  • In the ii-th round, the player selects a path p_ip\_i starting from s_is\_i 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 (i+1)(i + 1). 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 p_ip\_i is recorded as s_i+1s\_{i + 1}.
  • 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 ii paths p_1,…,p_ip\_1, \ldots, p\_i 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 p_1,…,p_kp\_1, \ldots, p\_k, the score of the game is defined as ∑_i=1ka_i∣p_i∣/k\sum\_{i = 1}^{k} a\_i \left|p\_i\right| / k, where ∣p_i∣|p\_i| represents the number of edges in path p_ip\_i, and a_ia\_i is the weight given in the input. Clearly, as the graph is acyclic, at most (n−1)(n-1) paths can be selected, so the input only provides the weights a_1,…,a_n−1a\_1, \ldots, a\_{n-1}.

Given the graph and the starting vertex, calculate the maximum achievable score in the game.

입력

The first line of input contains three integers, nn, mm, and s_1s\_1: the number of vertices, the number of edges, and the index of the starting vertex (2≤n≤1002 \le n \le 100; 1≤m≤n(n−1)21 \le m \le \frac{n (n - 1)}{2}; 1≤s_1≤n1 \le s\_1 \le n).

The second line contains (n−1)(n-1) integers a_1,…,a_n−1a\_1, \ldots, a\_{n-1}: the weights used to calculate the score (1≤a_1≤a_2≤…≤a_n−1≤1091 \le a\_1 \le a\_2 \le \ldots \le a\_{n - 1} \le 10^9).

Each of the next mm lines contains three integers, u_iu\_i, v_iv\_i, and w_iw\_i, describing a directed edge from u_iu\_i to v_iv\_i with weight w_iw\_i (1≤u_i,v_i≤n1 \le u\_i, v\_i \le n; u_i≠v_iu\_i \ne v\_i; 1≤w_i≤1091 \le w\_i \le 10^9). 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 p/qp/q where pp and qq are coprime integers and q>0q > 0. In this case, output pp and qq. Otherwise (if it is impossible to select any paths), output "-1~-1".

힌트

The selected doubling paths are p_1=((1,2))p\_1 = ((1, 2)) and p_2=((2,5))p\_2 = ((2, 5)).

예제2

  1. 예제 1

    입력
    5 5 1
    1 11 21 1211
    1 2 4
    1 3 11
    2 5 9
    3 4 12
    4 5 13
    
    예상 출력
    6 1
    
  2. 예제 2

    입력
    9 16 1
    1 10 100 1000 10000 100000 1000000 10000000
    1 2 2
    1 3 3
    2 3 5
    2 5 7
    3 4 11
    3 5 13
    3 6 17
    3 7 19
    4 7 23
    5 6 29
    5 8 31
    6 7 37
    6 8 41
    6 9 43
    7 9 47
    8 9 53
    
    예상 출력
    221 3