結果
| 問題 |
No.629 グラフの中に眠る門松列
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-05 21:28:34 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 4,000 ms |
| コード長 | 2,452 bytes |
| コンパイル時間 | 3,338 ms |
| コンパイル使用メモリ | 81,412 KB |
| 実行使用メモリ | 41,536 KB |
| 最終ジャッジ日時 | 2024-12-23 06:17:30 |
| 合計ジャッジ時間 | 8,681 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 36 |
ソースコード
import java.io.*;
import java.util.*;
class Main {
static ArrayList<Integer>[]g;
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n=sc.nextInt();
int m=sc.nextInt();
int[]a=sc.nextIntArray(n);
g=new ArrayList[n];
Arrays.setAll(g,x->new ArrayList<Integer>());
for(int i=0;i<m;++i){
int u=sc.nextInt()-1;
int v=sc.nextInt()-1;
g[u].add(v);
g[v].add(u);
}
for(int i=0;i<n;++i){
int s=g[i].size();
for(int j=0;j<s;++j){
int u=g[i].get(j);
for(int k=0;k<j;++k){
int v=g[i].get(k);
if(a[u]!=a[v]&&(a[u]-a[i])*(a[v]-a[i])>0){
out.println("YES");
out.close();
return;
}
}
}
}
out.println("NO");
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n){
int[]r=new int[n];
for(int i=0;i<n;++i)r[i]=nextInt();
return r;
}
}
}
夕叢霧香(ゆうむらきりか)