Submission #65439749


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define xx first
#define yy second
#define PB push_back
#define MP make_pair

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
template <typename T> using V = vector<T>;

template<class T> using uset = unordered_set<T>;
template<class T1, class T2> using umap = unordered_map<T1, T2>;

const vector<pair<int, int>> DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
constexpr int MOD = 1000000007;
mt19937_64 rnd(time(0));

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;

void dfs(int cur, auto& adjList, auto& vis) {
    if ( vis[cur] ) return;
    vis[cur] = true;
    for ( int adj: adjList[cur] ) {
        dfs(adj, adjList, vis);
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vvi adjList(n);
    int u, v;
    for ( int i=0; i<m; i++ ) {
        cin >> u >> v;
        u--; v--;
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    if ( m != n ) {
        cout << "No\n";
        return 0;
    }
    for ( int i=0; i<n; i++ ) {
        if ( adjList[i].size() != 2 ) {
            cout << "No\n";
            return 0;
        }
    }
    vector<bool> vis(n, false);
    dfs(0, adjList, vis);
    for ( int i=0; i<n; i++ ) {
        if ( !vis[i] ) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
	return 0;
}

Submission Info

Submission Time
Task C - Cycle Graph?
User din2009siuc
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1727 Byte
Status AC
Exec Time 108 ms
Memory 23476 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 3552 KiB
random_01.txt AC 58 ms 14128 KiB
random_02.txt AC 5 ms 4496 KiB
random_03.txt AC 99 ms 23468 KiB
random_04.txt AC 18 ms 9720 KiB
random_05.txt AC 89 ms 20952 KiB
random_06.txt AC 2 ms 4044 KiB
random_07.txt AC 94 ms 23472 KiB
random_08.txt AC 25 ms 11380 KiB
random_09.txt AC 62 ms 14212 KiB
random_10.txt AC 55 ms 13420 KiB
random_11.txt AC 108 ms 23476 KiB
random_12.txt AC 52 ms 15820 KiB
random_13.txt AC 71 ms 17688 KiB
random_14.txt AC 4 ms 4536 KiB
random_15.txt AC 101 ms 23460 KiB
random_16.txt AC 40 ms 14396 KiB
random_17.txt AC 3 ms 7948 KiB
random_18.txt AC 7 ms 6188 KiB
random_19.txt AC 17 ms 8960 KiB
random_20.txt AC 28 ms 7872 KiB
random_21.txt AC 63 ms 13972 KiB
sample_01.txt AC 1 ms 3676 KiB
sample_02.txt AC 1 ms 3584 KiB