Submission #65438902
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<fstream>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<array>
#include<unordered_set>
#include<unordered_map>
#include<cstring>
#include<string>
#include<memory>
#include<iomanip>
#include<cassert>
#include<cmath>
#include<random>
#include<algorithm>
#include<chrono>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#define ld long double
#define endl '\n'
using namespace std;
constexpr int N = 200'000;
vector<int> g[N];
int timer, tin[N], tout[N], parent[N];
int s = -1, t = -1;
void dfs(int u, int p) {
tin[u] = ++timer;
parent[u] = p;
for (int v : g[u]) {
if (v == p) continue;
if (tin[v] == 0) {
dfs(v, u);
}
else if (tout[v] == 0) {
s = v, t = u;
}
}
tout[u] = ++timer;
}
void solve() {
int n, m; cin >> n >> m;
for (int i = 0; i < n; i++) {
g[i].clear();
}
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v; u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
if (n != m) {
cout << "No" << endl;
return;
}
dfs(0, -1);
if (s == -1) {
cout << "No" << endl;
return;
}
int cur = t, cnt = 1;
while (cur != s) {
cnt++, cur = parent[cur];
}
cout << (cnt == n ? "Yes" : "No") << endl;
}
signed main() {
// freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// int q; cin >> q; while (q--)
solve();
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Cycle Graph? |
| User | lvovkir |
| Language | C++ 20 (gcc 12.2) |
| Score | 300 |
| Code Size | 1585 Byte |
| Status | AC |
| Exec Time | 116 ms |
| Memory | 34852 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| 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 | 3492 KiB |
| random_01.txt | AC | 90 ms | 32924 KiB |
| random_02.txt | AC | 8 ms | 6704 KiB |
| random_03.txt | AC | 107 ms | 34804 KiB |
| random_04.txt | AC | 22 ms | 13392 KiB |
| random_05.txt | AC | 91 ms | 30592 KiB |
| random_06.txt | AC | 3 ms | 4288 KiB |
| random_07.txt | AC | 95 ms | 34672 KiB |
| random_08.txt | AC | 31 ms | 16168 KiB |
| random_09.txt | AC | 101 ms | 33476 KiB |
| random_10.txt | AC | 89 ms | 29956 KiB |
| random_11.txt | AC | 116 ms | 34724 KiB |
| random_12.txt | AC | 55 ms | 22776 KiB |
| random_13.txt | AC | 91 ms | 24824 KiB |
| random_14.txt | AC | 5 ms | 5456 KiB |
| random_15.txt | AC | 112 ms | 34852 KiB |
| random_16.txt | AC | 42 ms | 20816 KiB |
| random_17.txt | AC | 2 ms | 3556 KiB |
| random_18.txt | AC | 8 ms | 6168 KiB |
| random_19.txt | AC | 19 ms | 9320 KiB |
| random_20.txt | AC | 33 ms | 9592 KiB |
| random_21.txt | AC | 59 ms | 15288 KiB |
| sample_01.txt | AC | 2 ms | 3568 KiB |
| sample_02.txt | AC | 2 ms | 3492 KiB |