CSES - HIIT Open 2019 - Results
Submission details
Task:Many Cycles
Sender:Piltit
Submission time:2019-05-25 15:59:43
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.30 sdetails
#20.02 sdetails

Compiler report

input/code.cpp: In function 'void dfs(int, int, std::vector<int>, int)':
input/code.cpp:13:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < p.size(); i++) {
                       ~~^~~~~~~~~~

Code

#include <iostream>
#include <vector>

using namespace std;

vector<int> v[101];
int t[101];
bool o[101];

void dfs(int x, int a, vector<int> p, int l) {
		if (o[x]) {
				if (x == a) {
						for (int i = 0; i < p.size(); i++) {
								t[p[i]]++;
						}
				}
				return;
		}
		o[x] = 1;
		p.push_back(x);

		

		for (auto u : v[x]) {
				if (u == l) continue;
				dfs(u, a, p, x);
		}
		o[x] = 0;
}

int main() {
		int w;
		cin >> w;
		while (w--) {
				int n, m, a, b;
				cin >> n >> m;
				for (int i = 0; i < m; i++) {
						cin >> a >> b;
						v[a].push_back(b);
						v[b].push_back(a);
				}
				
				for (int i = 1; i <= n; i++) {
						if (v[i].size() > 2) {
								for(int i=0;i<101;i++) o[i] = 0;
								dfs(i, i, {}, 0);
						}
				}
				for (int i = 1; i <= n; i++) {
						if (t[i] > 2) {
								cout << "YES" << endl;
								return 0;
						}
				}
				cout << "NO" << endl;
		}
}

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

Test 2

Verdict:

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

correct output
NO
NO
NO
YES
YES
...

user output
NO
YES