提出 #65446693


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long
#define PII pair<int,int>
#define mod 998244353
const int MOD=1e9+7;
const int N=1e5+10;
int read() {char act = 0;int f = 1, x= 0;while (act = getchar(), act < '0' && act != '-');if (act == '-') f = -1, act = getchar();x = act - '0';while (act = getchar(), act >= '0') x = x * 10 + act - '0';return x * f;}
vector<int>g[200010];
int du[200010];
bool f[200010];
void solve(){
    int n,m;
    cin>>n>>m;
    while(m--){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        du[u]++;
        du[v]++;
    }
    for(int i=1;i<=n;i++){
        if(du[i]!=2){
            cout<<"No"<<endl;
            return;
        }
    }
    queue<int>q;
    q.push(1);
    f[1]=true;
    int sumcnt=0;
    while(q.size()){
        int tt=q.front();
        q.pop();
        sumcnt++;
        for(auto i:g[tt]){
            if(!f[i]){
                f[i]=true;
                q.push(i);
            }
        }
    }
    if(sumcnt==n)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main()
{
    IOS;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

提出情報

提出日時
問題 C - Cycle Graph?
ユーザ Freakkk
言語 C++ 20 (gcc 12.2)
得点 300
コード長 1370 Byte
結果 AC
実行時間 78 ms
メモリ 16944 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 2 ms 3484 KiB
random_01.txt AC 57 ms 16380 KiB
random_02.txt AC 6 ms 4804 KiB
random_03.txt AC 67 ms 16180 KiB
random_04.txt AC 17 ms 7488 KiB
random_05.txt AC 68 ms 16308 KiB
random_06.txt AC 3 ms 3832 KiB
random_07.txt AC 77 ms 16228 KiB
random_08.txt AC 22 ms 8632 KiB
random_09.txt AC 71 ms 16144 KiB
random_10.txt AC 60 ms 15816 KiB
random_11.txt AC 77 ms 16068 KiB
random_12.txt AC 37 ms 11256 KiB
random_13.txt AC 69 ms 16216 KiB
random_14.txt AC 4 ms 4220 KiB
random_15.txt AC 78 ms 16172 KiB
random_16.txt AC 33 ms 10548 KiB
random_17.txt AC 2 ms 3480 KiB
random_18.txt AC 8 ms 6648 KiB
random_19.txt AC 19 ms 10340 KiB
random_20.txt AC 32 ms 10132 KiB
random_21.txt AC 64 ms 16944 KiB
sample_01.txt AC 2 ms 3484 KiB
sample_02.txt AC 2 ms 3500 KiB