PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000017. Núi vàng (The Mountain of Gold?)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Núi vàng (The Mountain of Gold?)

The Mountain of Gold?

Source: BOJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn mountains numbered 00 through n−1n-1, with mountain 00 being Ledang. Each of the mm one-way portals changes time by ww years when traversed. Every mountain is reachable from mountain 00. Determine whether one can start at mountain 00, traverse at least two portals, and return to mountain 00 at a strictly earlier time.

Input

The first line contains n,mn,m, followed by mm lines u,v,wu,v,w. Every edge connects two distinct vertices.

Output

Print possible if a strictly negative-time closed walk from mountain 00 back to itself exists; otherwise print not possible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le15; 0≤m≤600\le m\le60; −100≤w≤100-100\le w\le100; every vertex reachable from 00, no self-loops.

  • Subtask 2 (30 points): 1≤n≤801\le n\le80; 0≤m≤5000\le m\le500; −1000≤w≤1000-1000\le w\le1000; every vertex reachable from 00, no self-loops.

  • Subtask 3 (50 points): 1≤n≤10001\le n\le1000; 0≤m≤20000\le m\le2000; −1000≤w≤1000-1000\le w\le1000; every vertex reachable from 00, no self-loops.

Examples

Input

2 2
0 1 15
1 0 -20

Output

possible

Explanation

The route 0→1→00\to1\to0 changes time by 15−20=−515-20=-5, returning to mountain 00 five years earlier.