Submission #897428

# Submission time Handle Problem Language Result Execution time Memory
897428 2024-01-03T05:26:31 Z NeroZein Newspapers (CEOI21_newspapers) C++17
0 / 100
1 ms 6748 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 2e5 + 5;

int a, b; 
int pr[N];
int dep[N];
bool vis[N];
bool mark[N];
vector<int> g[N];

void check(int v, int p) {
  vis[v] = true;
  if (dep[v] >= dep[a]) {
    a = v;
  }
  for (int u : g[v]) {
    if (u == p) continue; 
    if (vis[u]) {
      cout << "NO" << '\n';
      exit(0);
    }
    dep[u] = dep[v] + 1; 
    check(u, v); 
  }
}

void dfs(int v, int p) {
  if (dep[v] >= dep[b]) {
    b = v;
  }
  for (int u : g[v]) {
    if (u == p) continue;
    dep[u] = dep[v] + 1; 
    pr[u] = v;
    dfs(u, v); 
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  check(1, 1);
  dep[a] = 0; 
  dfs(a, a);
  int x = b;
  while (x) {
    mark[x] = true; 
    x = pr[x];
  }
  for (int i = 1; i <= n; ++i) {
    if (g[i].size() > 1 && !mark[i]) {
      cout << "NO" << '\n';
      return 0; 
    }
  }
  cout << "YES" << '\n';
  cout << 0 << '\n'; 
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6744 KB Integer parameter [name=k] equals to 0, violates the range [1, 5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Integer parameter [name=k] equals to 0, violates the range [1, 5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6744 KB Integer parameter [name=k] equals to 0, violates the range [1, 5]
2 Halted 0 ms 0 KB -