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

17898번 - Ski Lifts 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB47181645.714%

문제

Last winter, an avalanche swept away all the ski lifts from the ski resort Valen. Instead of rebuilding the lifts like they were before, the plan is to do it in a more optimized way, and you are responsible for this.

The only thing remaining from the old lift system are n pylons situated at integer coordinates in the plane. You would like to put lifts in the form of line segments between some of these pylons. The line segments must satisfy the following constraints:

  1. A line segment can only go between pylons (x1, y1) and (x2, y2) if |y1 − y2| = 1.
  2. There are two types of pylons, one-way and two-way pylons. The one-way pylons can be connected to at most one other pylon, and the two-way pylons can be connected to at most two other pylons. However, if a two-way pylon i is connected to two other pylons, then they must be on opposite sides of i in the y-direction. In other words, the two pylons connected to i must have different y-coordinates.
  3. Two line segments may not intersect (except that the two line segments incident on a two-way pylon may touch at their endpoints).

What is the maximum number of ski lifts (line segments) you can place under these constraints?

입력

The first line contains one integer n (1 ≤ n ≤ 105). Each of the following n lines contains three integers x, y, and a, the coordinates and type of a pylon (0 ≤ x, y ≤ 105; a = 1 for a one-way pylon and a = 2 for a two-way pylon). All the pylons are situated at different coordinates.

출력

Output the maximum number of ski lift line segments that can be placed.

제한

예제 입력 1

8
1 0 1
3 0 2
0 1 1
2 1 2
4 1 2
1 2 2
2 3 1
4 3 1

예제 출력 1

4

예제 입력 2

4
0 0 1
100000 1 1
0 99999 1
100000 100000 1

예제 출력 2

2

힌트

출처

Contest > KTH Challenge > KTH Challenge 2019 F번

  • 문제를 만든 사람: Nils Gustafsson
(追記) (追記ここまで)

출처

대학교 대회

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

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