Submission #65434827


Source Code Expand

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

const int MOD=1e9+7;









int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
	
	cin>>n>>m;
	
	vector<vector<int>> gr(n+1);
	if(n!=m){
		cout<<"No";
		return 0; 
	}
	
	for(int i=0; i<m; i++){
		int x,y;
		cin>>x>>y;
		gr[x].push_back(y);
		gr[y].push_back(x);
		
		
	}
	
	queue<int> q;
	q.push(1);
	int cc=0;
	vector<int> vis(n+1);
	vis[1]=1;
	while(q.size()){
		int cur=q.front();
		q.pop();
		cc++;
		for(int y:gr[cur]){
			if(!vis[y]){
				vis[y]=1;
				q.push(y);
				
			}
		}
	}
	
	if(cc!=n){
		cout<<"No";
		return 0;
	}
	
	for(int i=1; i<=n; i++){
		if(gr[i].size()!=2){
			cout<<"No";
			return 0;
		}
	}
	
	
	
	
	
	cout<<"Yes";
	
	
    return 0;
}

Submission Info

Submission Time
Task C - Cycle Graph?
User usernameson
Language C++ 20 (gcc 12.2)
Score 300
Code Size 808 Byte
Status AC
Exec Time 56 ms
Memory 15012 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 3384 KiB
random_01.txt AC 52 ms 14892 KiB
random_02.txt AC 5 ms 4340 KiB
random_03.txt AC 53 ms 14940 KiB
random_04.txt AC 14 ms 6680 KiB
random_05.txt AC 54 ms 14588 KiB
random_06.txt AC 2 ms 3688 KiB
random_07.txt AC 53 ms 14956 KiB
random_08.txt AC 19 ms 7832 KiB
random_09.txt AC 56 ms 14952 KiB
random_10.txt AC 51 ms 14072 KiB
random_11.txt AC 56 ms 14916 KiB
random_12.txt AC 28 ms 10560 KiB
random_13.txt AC 50 ms 15012 KiB
random_14.txt AC 3 ms 3888 KiB
random_15.txt AC 56 ms 14548 KiB
random_16.txt AC 26 ms 9596 KiB
random_17.txt AC 3 ms 7788 KiB
random_18.txt AC 2 ms 4488 KiB
random_19.txt AC 2 ms 6188 KiB
random_20.txt AC 2 ms 4900 KiB
random_21.txt AC 3 ms 7556 KiB
sample_01.txt AC 1 ms 3488 KiB
sample_02.txt AC 1 ms 3540 KiB