結果

問題 No.1610 She Loves Me, She Loves Me Not, ...
ユーザー merlin
提出日時 2021-07-21 22:12:10
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,439 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 81,012 KB
実行使用メモリ 56,816 KB
最終ジャッジ日時 2024-07-17 18:55:01
合計ジャッジ時間 5,975 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();

        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]);
        ArrayList<Integer> g[]=new ArrayList[n];
        int i,c[]=new int[n];
        for(i=0;i<n;i++) g[i]=new ArrayList<>();
        for(i=0;i<m;i++)
        {
            s=bu.readLine().split(" ");
            int u=Integer.parseInt(s[0])-1,v=Integer.parseInt(s[1])-1;
            g[u].add(v); g[v].add(u);
            c[u]++; c[v]++;
        }

        int ans=0;
        PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[1]>o2[1]) return 1;
                else return -1;
            }});
        for(i=0;i<n;i++) pq.add(new int[]{i,c[i]});
        while(!pq.isEmpty())
        {
            int a[]=pq.poll();
            if(c[a[0]]==0 || c[a[0]]<a[1]) continue;
            ans++;
            c[a[0]]=0;
            for(int x:g[a[0]])
            {
                c[x]--;
                if(c[x]>0) pq.add(new int[]{x,c[x]});
            }
        }

        if(ans%2==0) sb.append("No");
        else sb.append("Yes");
        System.out.println(sb);
    }
}
0