CSES - HIIT Open 2019 - Results
Submission details
Task:Many Cycles
Sender:.*
Submission time:2019-05-25 14:52:00 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.03 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];
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(lvl[u] > lvl[s])
				continue;
			int k = s;
			sy[k]++;
			if(sy[k] == 2) {
				y = true;
			}
			while(k != u) {
				k = par[k];
				sy[k]++;
				if(sy[k] == 2) {
					y = true;
				}
			}
			continue;
		}
		par[u] = s;
		lvl[u] = lvl[s]+1;
		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();
			sy[i] = 0;
			z[i] = 0;
		}
		lvl[1] = 1;
		for(int i=0; i<m; i++) {
			cin >> a >> b;
			vrk[a].push_back(b);
			vrk[b].push_back(a);
		}
		haku(1,0);
		if(y)
			cout << "YES";
		else
			cout << "NO";
		cout << "\n";
	}
}

Test details

Test 1

Verdict:

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

correct output
YES
YES
YES
YES
NO
...

user output
YES
NO
NO
NO
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
...