結果
| 問題 |
No.629 グラフの中に眠る門松列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-06 15:27:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 321 ms / 4,000 ms |
| コード長 | 1,247 bytes |
| コンパイル時間 | 4,003 ms |
| コンパイル使用メモリ | 80,324 KB |
| 実行使用メモリ | 47,588 KB |
| 最終ジャッジ日時 | 2024-12-23 08:35:12 |
| 合計ジャッジ時間 | 14,112 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 36 |
ソースコード
import java.io.*;
import java.util.*;
public class Main_yukicoder629 {
private static Scanner sc;
private static Printer pr;
private static void solve() {
int n = sc.nextInt();
int m = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
List<List<Integer>> edges = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
edges.add(new ArrayList<>());
}
for (int i = 0; i < m; i++) {
int u = sc.nextInt() - 1;
int v = sc.nextInt() - 1;
edges.get(u).add(v);
edges.get(v).add(u);
}
for (int i = 0; i < n; i++) {
int x2 = a[i];
if (edges.get(i).size() >= 2) {
for (int e1 : edges.get(i)) {
int x1 = a[e1];
for (int e2 : edges.get(i)) {
int x3 = a[e2];
if ((x2 > x1 && x2 > x3 && x1 != x3) || (x2 < x1 && x2 < x3 && x1 != x3)) {
pr.println("YES");
return;
}
}
}
}
}
pr.println("NO");
}
// ---------------------------------------------------
public static void main(String[] args) {
sc = new Scanner(System.in);
pr = new Printer(System.out);
solve();
pr.close();
sc.close();
}
private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}