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

Code

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long LL;



void isok(vector<vector<int>> & adj, vector<bool> & seen, int node, int start, int & seenstart, int prevnode) {
  seen[node] = true;
  for (auto nb : adj[node]) {
    if (nb == start && start != prevnode) {
      seenstart++;
    }
    if (!seen[nb]) {
      isok(adj, seen, nb, start, seenstart, node);
    }
  }
  return;
}



int main() {
 int tests; cin>>tests;
 while (tests--) {
  int n,edges; cin>>n>>edges;
  vector<vector<int>> adj(n);
  while(edges--) {
   int start, end; cin>>start>>end;
   start--;end--;
   adj[start].emplace_back(end);
   adj[end].emplace_back(start);
  }
  bool isbi = false;
  for (int node = 0; node < n; node++) {
    vector<bool> seen(n);
    int seenstart = 0;
    isok(adj, seen, node, node, seenstart, -1);

    if (seenstart >= 2) {
      isbi = true;
      break;
    }
  }
  if (isbi) {
    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: 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
...