CSES - HIIT Open 2019 - Results
Submission details
Task:Many Cycles
Sender:.*
Submission time:2019-05-25 15:01:25 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.03 sdetails

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define M 1000000007
#define N (1<<18)
#define P complex<long long>
#define X real()
#define Y imag()
 
using namespace std;

int t, n, m, z[111],par[111], sy[101], a, b, lvl[111],np,cnt;
bool y;
vector<int> vrk[111];

void haku(int s, int e) {
	if(z[s])
		return;
	z[s] = 1;
	for(auto u:vrk[s]) {
		if(u == e)
			continue;
		if(z[u]) {
			if(u == np)
				cnt++;
			continue;
		}
		haku(u, s);
	}
}

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> t;
	for(int g=0; g<t; g++) {
		cin >> n >> m;
			y = false;
		for(int i=1; i<=n; i++) {
			vrk[i].clear();
		}
		for(int i=0; i<m; i++) {
			cin >> a >> b;
			vrk[a].push_back(b);
			vrk[b].push_back(a);
		}
		for(int i=1; i<=n; i++) {
			np = i;
			cnt = 0;
			for(int j=1; j<=n; j++)
				z[j] = 0;
			haku(i, 0);
			if(cnt >= 2)
				y = true;
		}
		if(y)
			cout << "YES";
		else
			cout << "NO";
		cout << "\n";
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
100 78
97 68
75 90
58 80
...

correct output
YES
YES
YES
YES
NO
...

user output
YES
YES
YES
YES
NO
...
Truncated

Test 2

Verdict: ACCEPTED

input
11
2 1
1 2
6 6
1 2
...

correct output
NO
NO
NO
YES
YES
...

user output
NO
NO
NO
YES
YES
...