結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
sca1l
|
| 提出日時 | 2017-10-28 00:11:58 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,670 bytes |
| コンパイル時間 | 2,187 ms |
| コンパイル使用メモリ | 78,192 KB |
| 実行使用メモリ | 64,452 KB |
| 最終ジャッジ日時 | 2024-11-21 23:53:24 |
| 合計ジャッジ時間 | 16,679 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 TLE * 2 |
ソースコード
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] c = new int[n];
ArrayList[] x = new ArrayList[n];
for(int i=0; i<n; i++){
x[i] = new ArrayList<Integer>();
}
int at = 0;
for(int i=0; i<m; i++){
int a = sc.nextInt();
int b = sc.nextInt();
x[a].add(b);
x[b].add(a);
c[a]++;
c[b]++;
at = a;
}
int con = 0;
ArrayList<Integer> q = new ArrayList<Integer>();
q.add(at);
boolean[] ch = new boolean[n];
while(q.size()>0){
int now = q.remove(0);
ch[now] = true;
for(int i=0; i<x[now].size(); i++){
int ne = (int)x[now].get(i);
if(ch[ne]){
continue;
}
q.add(ne);
Set<Integer> set = new HashSet<Integer>(q);
q = new ArrayList<Integer>(set);
}
con++;
}
int uni = 0;
int odd = 0;
for(int i=0; i<n; i++){
if(c[i]%2==1){
odd++;
}
if(c[i]>0){
uni++;
}
}
if(con<uni){
System.out.println("NO");
System.exit(0);
}
if(odd==0 || odd==2){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
sca1l