結果

問題 No.629 グラフの中に眠る門松列
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-05 21:28:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 145 ms / 4,000 ms
コード長 2,452 bytes
コンパイル時間 2,794 ms
コンパイル使用メモリ 86,684 KB
実行使用メモリ 54,384 KB
最終ジャッジ日時 2023-08-24 20:28:40
合計ジャッジ時間 8,145 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
50,088 KB
testcase_01 AC 56 ms
51,004 KB
testcase_02 AC 55 ms
49,996 KB
testcase_03 AC 54 ms
50,392 KB
testcase_04 AC 54 ms
50,024 KB
testcase_05 AC 54 ms
49,920 KB
testcase_06 AC 54 ms
50,676 KB
testcase_07 AC 54 ms
50,544 KB
testcase_08 AC 54 ms
49,932 KB
testcase_09 AC 54 ms
50,044 KB
testcase_10 AC 54 ms
50,044 KB
testcase_11 AC 54 ms
49,992 KB
testcase_12 AC 55 ms
50,100 KB
testcase_13 AC 55 ms
50,060 KB
testcase_14 AC 55 ms
50,060 KB
testcase_15 AC 54 ms
50,544 KB
testcase_16 AC 54 ms
50,092 KB
testcase_17 AC 54 ms
50,296 KB
testcase_18 AC 54 ms
49,988 KB
testcase_19 AC 55 ms
50,920 KB
testcase_20 AC 54 ms
50,392 KB
testcase_21 AC 115 ms
53,200 KB
testcase_22 AC 90 ms
52,372 KB
testcase_23 AC 105 ms
52,672 KB
testcase_24 AC 116 ms
52,384 KB
testcase_25 AC 145 ms
54,384 KB
testcase_26 AC 140 ms
53,416 KB
testcase_27 AC 125 ms
53,564 KB
testcase_28 AC 81 ms
51,164 KB
testcase_29 AC 111 ms
53,184 KB
testcase_30 AC 130 ms
53,300 KB
testcase_31 AC 127 ms
53,264 KB
testcase_32 AC 113 ms
53,172 KB
testcase_33 AC 132 ms
53,004 KB
testcase_34 AC 118 ms
53,976 KB
testcase_35 AC 111 ms
53,024 KB
testcase_36 AC 123 ms
52,928 KB
testcase_37 AC 120 ms
53,044 KB
testcase_38 AC 112 ms
53,472 KB
testcase_39 AC 117 ms
52,756 KB
testcase_40 AC 104 ms
52,624 KB
testcase_41 AC 99 ms
52,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }
    }
}
0