Submission #65437367


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
const ll oo=*(ll*)"?????????????????????????????????";
using dd=double;
const dd eps=1e-9;

using vl=vector<ll>;
using vvl=vector<vl>;
#define sz(x) ll((x).size())
#define all(x) begin(x),end(x)
#define pb push_back

#define mp make_pair
#define xx first
#define yy second

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORD(i,a,b) for(ll i=(b)-1;i>=(a);i--)

#define TR(X) ({ if(1) cerr << __LINE__ << ": " #X " = " << (X) << endl; })

void solve(){
	ll n,m; cin >> n >> m;
	vvl adj(n);
	
	FOR(j,0,m) {
		ll a,b; cin >> a >> b; a--; b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	ll last=-1;
	ll cur=0;
	ll cnt=0;
	for(;;) {
		if(sz(adj[cur]) != 2) {
			cout << "No" << endl;
			return;
		}
		
		tie(cur,last) = mp(adj[cur][last==adj[cur][0]],cur);
		cnt++;
		if(cur == 0) {
			if(cnt == n) cout << "Yes" << endl;
			else cout << "No" << endl;
			return;
		}
		if(cnt == n) {
			cout << "No" << endl;
			return;
		}
		
	}
}

int main() { cin.sync_with_stdio(0); cin.tie(0);
	
	
	ll t=1; //cin >> t;
	while(t--) solve();
}

Submission Info

Submission Time
Task C - Cycle Graph?
User qusol
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1154 Byte
Status AC
Exec Time 56 ms
Memory 14900 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 3360 KiB
random_01.txt AC 46 ms 14328 KiB
random_02.txt AC 4 ms 4328 KiB
random_03.txt AC 56 ms 14092 KiB
random_04.txt AC 15 ms 6476 KiB
random_05.txt AC 52 ms 14112 KiB
random_06.txt AC 2 ms 3576 KiB
random_07.txt AC 54 ms 14220 KiB
random_08.txt AC 19 ms 7624 KiB
random_09.txt AC 44 ms 14384 KiB
random_10.txt AC 41 ms 13920 KiB
random_11.txt AC 54 ms 14184 KiB
random_12.txt AC 31 ms 9860 KiB
random_13.txt AC 47 ms 14128 KiB
random_14.txt AC 3 ms 3832 KiB
random_15.txt AC 55 ms 14288 KiB
random_16.txt AC 27 ms 9132 KiB
random_17.txt AC 3 ms 7824 KiB
random_18.txt AC 7 ms 5880 KiB
random_19.txt AC 15 ms 8744 KiB
random_20.txt AC 27 ms 9156 KiB
random_21.txt AC 45 ms 14900 KiB
sample_01.txt AC 1 ms 3456 KiB
sample_02.txt AC 1 ms 3384 KiB