Submission #65435317


Source Code Expand

// Problem: 'C - Cycle Graph?'
// Contest: 'AtCoder - AtCoder Beginner Contest 404'
// URL: 'https://atcoder.jp/contests/abc404/tasks/abc404_c'
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by competitive-companion.el (https://github.com/luishgh/competitive-companion.el)

#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MAX = 2e5 + 10;

vector<int> g[MAX];
int d[MAX];
int v[MAX];

int main() {_;

  int n, m; cin >> n >> m;

  for (int i = 0; i < n; i++) d[i] = 0, v[i] = 0;

  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  if (m != n) {
    cout << "No" << endl;
    exit(0);
  }

  queue<int> q;
  q.push(0);

  while (q.size()) {
    auto u = q.front();
    q.pop();
    v[u] = true;
    for (auto w : g[u]) if (!v[w]) q.push(w);
  }

  for (int i = 0; i < n; i++) {
    if (g[i].size() != 2 or !v[i]) {
      cout << "No" << endl;
      exit(0);
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Submission Info

Submission Time
Task C - Cycle Graph?
User luishgh
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1234 Byte
Status AC
Exec Time 52 ms
Memory 16020 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 2 ms 3400 KiB
random_01.txt AC 50 ms 15968 KiB
random_02.txt AC 6 ms 4948 KiB
random_03.txt AC 51 ms 15896 KiB
random_04.txt AC 15 ms 7460 KiB
random_05.txt AC 49 ms 15976 KiB
random_06.txt AC 3 ms 3712 KiB
random_07.txt AC 50 ms 15920 KiB
random_08.txt AC 18 ms 8504 KiB
random_09.txt AC 51 ms 15924 KiB
random_10.txt AC 47 ms 15340 KiB
random_11.txt AC 52 ms 16020 KiB
random_12.txt AC 29 ms 11280 KiB
random_13.txt AC 47 ms 15960 KiB
random_14.txt AC 4 ms 4452 KiB
random_15.txt AC 51 ms 15920 KiB
random_16.txt AC 27 ms 10384 KiB
random_17.txt AC 2 ms 5168 KiB
random_18.txt AC 7 ms 6636 KiB
random_19.txt AC 16 ms 10168 KiB
random_20.txt AC 26 ms 8780 KiB
random_21.txt AC 44 ms 15876 KiB
sample_01.txt AC 2 ms 3492 KiB
sample_02.txt AC 2 ms 3400 KiB