Potential well

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

요약
가중치가 있는 유향 그래프에서 각 정점에 퍼텐셜을 부여해 조정된 간선 가중치의 최솟값을 최대화하고, 무한히 크게 만들 수 있으면 +inf를 출력한다.
난이도

어려움10점 중 8점

유형
최단 경로, 그래프, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Billionaire Christian has learned today about Dijkstra's algorithm with Johnson potentials. He liked it so much that he decided to add potentials to all of his favourite graphs.

Christian's tastes are very singular --- he keeps in his secret room only directed weighted graphs.

A little reminder about potentials: each vertex vv will be assigned with its potential ϕ(v)\phi(v). If there was an edge from uu to vv with initial weight ww then its new weight will be w′=w−ϕ(v)+ϕ(u)w' = w - \phi(v) + \phi(u).

Strength of a graph is defined as a minimum of its edges weights.

Christian don't want weak graphs in his room, so he want to choose potentials in such way that its strength is maximized.

입력

First line contains two integers nn (2≤n≤1032 \le n \le 10^3) and mm (1≤m≤1051 \le m \le 10^5) --- number of vertices and edges in Christian's favourite graph. Next mm lines contain triples of integers u_i,v_i,w_iu\_i\\, v\_i\\, w\_i (1≤u_i,,v_i≤n1 \le u\_i,\\, v\_i \le n, ∣w_i∣≤106|w\_i| \le 10^6) --- ii-th edge goes from a_ia\_i to b_ib\_i and has weight w_iw\_i.

출력

First line shoult contain maximum strength of the graph. If it is possible to make the answer infinitely big then output +inf instead.

If the answer is finite then second line should contain potentials of vertices. They shouldn't exceed 101010^{10} by absolute value. Your answer should differ from the correct one and also from the answer computed based on your potentials no more than 10−510^{-5}.

예제2

  1. 예제 1

    입력
    3 3
    1 2 1
    2 3 1
    3 1 1
    
    예상 출력
    1.0
    0.0 0.0 0.0
    
  2. 예제 2

    입력
    2 1
    1 2 1
    
    예상 출력
    +inf