問題一覧 > 通常問題

No.3031 Orientation of Surfaces

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 35
作問者 : ジュ・ビオレ・グレイス / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 11868 / 自分の提出
問題文最終更新日: 2026-10-22 16:46:51
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 457 (順位表) の他の問題:

Note

This is a problem where you print YES or NO.

Problem Statement

You are given $M$ triples of integers $A_m, B_m, C_m$ satisfying $1 \leq A_m < B_m < C_m \leq 10^8$ from the input.
Let $\Delta_m = \{ A_m, B_m, C_m\}$ and let $\mathcal T = \{ \Delta_1, \dots, \Delta_M \}$.
Here, the $\Delta_m$ are given so that they are pairwise distinct.

An "orientation" of $\Delta = \{ A, B, C \}\ (A < B < C)$ refers to either of the following:

  • the function $\sigma : \Delta \rightarrow \Delta$ defined by $\sigma(A) = B, \ \sigma(B) = C, \ \sigma(C) = A$
  • the function $\sigma : \Delta \rightarrow \Delta$ defined by $\sigma(A) = C, \ \sigma(B) = A, \ \sigma(C) = B$

We say that "$\mathcal T$ is orientable" if an orientation $\sigma_m$ of each $\Delta_m \in \mathcal T$ can be chosen so that the following condition holds:

  • For any $A, B \in \Delta_m \cap \Delta_n \ (n \neq m)$, $\sigma_m(A) = B \Leftrightarrow \sigma_n(B) = A.$

Print YES if $\mathcal T$ is orientable, and NO otherwise.

Background

In topology, an orientation of a surface is, intuitively, a choice of "front and back". For example, a front and a back cannot be determined for a Möbius strip. Consider a "triangulation", which divides a surface into small triangles.
A triangle has a front and a back; we regard the front as the face on the side toward which a right-handed screw moves when it is rotated in the rotational direction of the vertices. A surface is said to be "orientable" when the fronts can be determined so that the front faces of adjacent triangles agree.
This problem asks you to determine whether a triangulation is orientable or not, from data consisting only of the information on its vertices.

Input

$M$
$A_1 \ B_1 \ C_1$
$\vdots$
$A_M \ B_M \ C_M$

$1 \leq M \leq 10^5,$
$1 \leq A_m < B_m < C_m \leq 10^8$

Output

Print a newline at the end.

Sample

Sample 1
Input
1
1 2 3
Output
YES

It is clearly orientable.

Sample 2
Input
3
1 2 3
1 2 4
1 2 5
Output
NO

The edge consisting of $1 \ 2$ is shared by three triangles, so it is not orientable.

Sample 3
Input
18
1 2 4
2 4 6
2 3 6
3 6 7
1 3 7
1 4 7
4 5 6
5 6 8
6 7 8
7 8 9
4 7 9
4 5 9
1 5 8
1 2 8
2 8 9
2 3 9
3 5 9
1 3 5
Output
YES

This is a triangulation of a surface called a torus, and it is orientable.
The same vertices and edges appear more than once; this represents a triangulation on the figure obtained by gluing opposite sides of a square together in the same direction.
Ideally the torus itself should be drawn, but for simplicity it is illustrated on its development.

Sample 4
Input
6
1 2 3
2 3 5
3 4 5
4 5 6
2 4 6
1 2 6
Output
NO

This is a triangulation of a Möbius strip. A Möbius strip is not orientable.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。