CSES - HIIT Open 2019 - Results
Submission details
Task:Many Cycles
Sender:Varokaa J:tä
Submission time:2019-05-25 11:37:48 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#20.02 sdetails

Code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1010
vector<int> v[N];
int t[N], h[N];
bool f = 0;

void haku(int s, int hh){
    h[s] = hh;
    int k = 0;
    for(int i : v[s]){
        if(h[i] == 0){
            haku(i, hh+1);
            t[s] += t[i];
            if(t[i]) ++k;
        }else if(h[i] < hh-1) {
            --t[i];
            ++t[s];
        }
    }
    if(k > 1 || t[s] > 1) f = 1;
}

int main() {
    int T; cin >> T;
    while(T--){
        int n, m; cin >> n >> m;
        for(int i=1; i<=n; ++i) {
            v[i].clear();
            h[i] = t[i] = 0;
        }
        for(int i=0; i<m; ++i){
            int a, b; cin >> a >> b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        f=0;
        for(int i=1; i<=n; ++i) if(!h[i]) haku(i, 1);
        if(f) cout << "YES\n";
        else cout << "NO\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:

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

correct output
NO
NO
NO
YES
YES
...

user output
NO
NO
NO
YES
NO
...