Logo
(追記) (追記ここまで)

16842번 - Directions 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB36131340.625%

문제

Initially, Snuke can’t move at all. There are n tickets, and the price of the i-th ticket is pi. If Snuke buys the i-th ticket, for all points (x, y) and a nonnegative number t, he can move from (x, y) to (x + tai, y + tbi). Snuke wants to buy tickets and he wants to be able to travel between any two points. Compute the minimal possible total price of the tickets he must buy.

입력

First line of the input contains one integer n (1 ≤ n ≤ 2 · 105). Then n lines follow; i’th of these lines contains three integers ai, bi, pi (−109 ≤ ai, bi ≤ 109, 1 ≤ pi ≤ 109).

출력

Print the minimal possible total price of the tickets he must buy in order to be able to move between any two points. If this is impossible, print −1 instead.

제한

예제 입력 1

7
0 3 1
0 3 2
1 -1 2
0 0 1
-2 4 1
-4 0 1
2 1 2

예제 출력 1

4

예제 입력 2

2
1 2 3
4 5 6

예제 출력 2

-1

힌트

In the Sample 1 you can, for example, buy tickets 1, 3, 6.

출처

Contest > ICPC Japanese Alumni Group > JAG Summer Camp > JAG Summer Camp 2014 Day 2 F번

Camp > Petrozavodsk Programming Camp > Winter 2015 > Day 2: Makoto Soejima Contest 1, Japanese Grand Prix F번

Contest > Open Cup > 2014/2015 Season > Stage 6: Grand Prix of Japan F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /