結果
| 問題 |
No.408 五輪ピック
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-06 10:03:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 568 ms / 5,000 ms |
| コード長 | 3,026 bytes |
| コンパイル時間 | 5,865 ms |
| コンパイル使用メモリ | 80,080 KB |
| 実行使用メモリ | 56,284 KB |
| 最終ジャッジ日時 | 2024-11-07 02:57:56 |
| 合計ジャッジ時間 | 17,115 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
import java.io.*;
import java.util.*;
public class Main_yukicoder408_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Printer pr = new Printer(System.out);
int n = sc.nextInt();
int m = sc.nextInt();
List<List<Integer>> edges = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
edges.add(new ArrayList<>());
}
int[] a = new int[m];
int[] b = new int[m];
for (int i = 0; i < m; i++) {
a[i] = sc.nextInt() - 1;
b[i] = sc.nextInt() - 1;
// if (edges.get(a[i]) == null) {
// edges.set(a[i], new ArrayList<>());
// }
// if (edges.get(b[i]) == null) {
// edges.set(b[i], new ArrayList<>());
// }
edges.get(a[i]).add(b[i]);
edges.get(b[i]).add(a[i]);
}
List<List<Integer>> edges2 = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
edges2.add(new ArrayList<>(edges.get(i).size()));
}
for (int e : edges.get(0)) {
for (int e2 : edges.get(e)) {
if (e2 != 0) {
// if (edges2.get(e2) == null) {
// edges2.set(e2, new ArrayList<>(edges.get(e2).size()));
// }
edges2.get(e2).add(e);
}
}
}
for (int i = 1; i < m; i++) {
int ii = a[i];
int jj = b[i];
// if (ii == 0 || jj == 0 || edges2.get(ii) == null || edges2.get(jj) == null) {
if (ii == 0 || jj == 0 || edges2.get(ii).size() == 0 || edges2.get(jj).size() == 0) {
continue;
}
for (int e : edges2.get(ii)) {
if (e == 0) {
continue;
}
for (int e2 : edges2.get(jj)) {
if (e2 == 0) {
continue;
}
if (e != e2 && e != jj && e2 != ii) {
pr.println("YES");
pr.close();
sc.close();
return;
}
}
}
}
pr.println("NO");
pr.close();
sc.close();
}
@SuppressWarnings("unused")
private static class Scanner {
BufferedReader br;
Iterator<String> it;
Scanner (InputStream in) {
br = new BufferedReader(new InputStreamReader(in), 128);
}
String next() throws RuntimeException {
try {
if (it == null || !it.hasNext()) {
// it = Arrays.asList(br.readLine().split(" ")).iterator();
it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
}
return it.next();
} catch (IOException e) {
throw new IllegalStateException();
}
}
int nextInt() throws RuntimeException {
return Integer.parseInt(next());
}
long nextLong() throws RuntimeException {
return Long.parseLong(next());
}
float nextFloat() throws RuntimeException {
return Float.parseFloat(next());
}
double nextDouble() throws RuntimeException {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
// throw new IllegalStateException();
}
}
}
private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}