結果

問題 No.583 鉄道同好会
ユーザー ianlinathomeianlinathome
提出日時 2017-11-10 06:51:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 25,472 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 11:19:07
合計ジャッジ時間 1,112 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 0 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 7 ms
6,940 KB
testcase_13 AC 7 ms
6,944 KB
testcase_14 AC 7 ms
6,944 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 17 ms
6,944 KB
testcase_17 AC 20 ms
6,944 KB
testcase_18 AC 20 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int find(int n,int p[]){
    if(p[n]==n)return n;
    return p[n]=find(p[n],p);
}
int main(){
    int p[1000],n,m,l,r,ans=-1,a[1000];
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        p[i]=-1;
        a[i]=0;
    }
    for(int i=0;i<m;i++){
        scanf("%d%d",&l,&r);
        a[l]++;
        a[r]++;
        if(p[l]==-1)p[l]=l;
        if(p[r]==-1)p[r]=r;
        l=find(l,p);
        r=find(r,p);
        if(l>r)p[l]=r;
        else p[r]=l;
    }
    for(int i=0;i<n;i++){
        if(find(p[i],p)!=-1){
            if(ans==-1)ans=find(p[i],p);
            else if(ans!=find(p[i],p)){
                printf("NO\n");
                return 0;
            }
        }
        else ans=find(p[i],p);
    }
    ans=0;
    for(int i=0;i<n;i++)if(a[i]%2==1)ans++;
    if(ans>2)printf("NO\n");
    else printf("YES\n");
}
0