Submission #65462733


Source Code Expand

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <map>
#include <set>

#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define _sz(x) ((int)x.size())
#define pii pair<int, int>
#define mpair make_pair
#define ld long double
#define vi vector<int>
#define ll long long
#define ss second
#define ff first

using namespace std;

const ll lINF = 1000000000000000007;
const int iINF = 1000000007;
const int INF = 1e5+1;

/*
*/
// 

vector<int> g;
vector<vector<int>> gr;
vector<bool> visited;

void dfs(int cur) {
    visited[cur] = true;
    for(int neighbor : gr[cur]) {
        if(!visited[neighbor]) dfs(neighbor);
    }
}


void solve(){
    int n, m;   
    cin >> n >> m;
    g.resize(n+1);
    gr.resize(n+1);
    visited.resize(n+1);

    for(int i = 0; i < m; ++ i){
        int x, y;
        cin >> x >> y; 
        gr[x].push_back(y);
        gr[y].push_back(x);
        g[x] ++;
        g[y] ++;
    }

    bool l = false;
    for(int i = 1; i <= n; ++ i){
        if(g[i] != 2){
            l = true;
            break;
        }
    }
    if(l){
        cout << "No";
        return ;
    }

    dfs(1);

    for(int i = 1; i <= n; ++ i){
        if(!visited[i]){
            cout << "No";
            return ;
        }
    }

    cout << "Yes";

}


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int tt = 1; 
	// cin >> tt;
	while(tt --){
		solve();
		cout << '\n';
	}
	
	return 0;	
}

Submission Info

Submission Time
Task C - Cycle Graph?
User dusanov
Language C++ 17 (gcc 12.2)
Score 300
Code Size 1666 Byte
Status AC
Exec Time 67 ms
Memory 24240 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 24
Set Name Test Cases
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
Case Name Status Exec Time Memory
min.txt AC 1 ms 3616 KiB
random_01.txt AC 47 ms 14876 KiB
random_02.txt AC 5 ms 4428 KiB
random_03.txt AC 67 ms 24168 KiB
random_04.txt AC 18 ms 9676 KiB
random_05.txt AC 62 ms 21784 KiB
random_06.txt AC 2 ms 4000 KiB
random_07.txt AC 65 ms 24240 KiB
random_08.txt AC 23 ms 11820 KiB
random_09.txt AC 45 ms 14840 KiB
random_10.txt AC 43 ms 14200 KiB
random_11.txt AC 65 ms 24084 KiB
random_12.txt AC 38 ms 16260 KiB
random_13.txt AC 53 ms 18368 KiB
random_14.txt AC 4 ms 4552 KiB
random_15.txt AC 66 ms 24116 KiB
random_16.txt AC 32 ms 15092 KiB
random_17.txt AC 3 ms 8540 KiB
random_18.txt AC 7 ms 5896 KiB
random_19.txt AC 16 ms 9456 KiB
random_20.txt AC 26 ms 8072 KiB
random_21.txt AC 48 ms 14660 KiB
sample_01.txt AC 1 ms 3496 KiB
sample_02.txt AC 1 ms 3444 KiB