提出 #65459333


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
int n,m;
int degree[200000+5];
int fa[200000+5];
set<int> s;
int find(int k){
	return fa[k]==k?k:fa[k]=find(fa[k]);
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) fa[i]=i;
    if(n!=m){
        cout<<"No";
        return 0;
    }
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        degree[a]++,degree[b]++;
        if(find(a)!=find(b)) fa[find(a)]=find(b);
        if(degree[a]>2||degree[b]>2){
            cout<<"No";
            return 0;
        }
    }
    for(int i=1;i<=n;i++){
    	s.insert(find(i));
	}
	if(s.size()==1) cout<<"Yes";
	else cout<<"No";
}

提出情報

提出日時
問題 C - Cycle Graph?
ユーザ xiaoke2023
言語 C++ 20 (gcc 12.2)
得点 300
コード長 663 Byte
結果 AC
実行時間 77 ms
メモリ 5200 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 24
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3512 KiB
random_01.txt AC 4 ms 5116 KiB
random_02.txt AC 2 ms 3664 KiB
random_03.txt AC 75 ms 5104 KiB
random_04.txt AC 22 ms 4060 KiB
random_05.txt AC 76 ms 5200 KiB
random_06.txt AC 3 ms 3484 KiB
random_07.txt AC 76 ms 4992 KiB
random_08.txt AC 28 ms 4132 KiB
random_09.txt AC 3 ms 5040 KiB
random_10.txt AC 4 ms 4960 KiB
random_11.txt AC 75 ms 5100 KiB
random_12.txt AC 45 ms 4432 KiB
random_13.txt AC 77 ms 5044 KiB
random_14.txt AC 5 ms 3656 KiB
random_15.txt AC 76 ms 5016 KiB
random_16.txt AC 40 ms 4336 KiB
random_17.txt AC 1 ms 4340 KiB
random_18.txt AC 1 ms 3712 KiB
random_19.txt AC 1 ms 4096 KiB
random_20.txt AC 1 ms 3920 KiB
random_21.txt AC 1 ms 4260 KiB
sample_01.txt AC 1 ms 3688 KiB
sample_02.txt AC 1 ms 3620 KiB