Submission #1054417

#TimeUsernameProblemLanguageResultExecution timeMemory
1054417kunzaZa183Newspapers (CEOI21_newspapers)C++17
4 / 100
7 ms612 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; if (m >= n) { cout << "NO\n"; return 0; } const int maxn = 1000; vector<int> adjlist[maxn]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; adjlist[a].push_back(b), adjlist[b].push_back(a); } function<int(int, int)> dfs = [&](int cur, int par) { int maxi = 0; for (auto a : adjlist[cur]) if (a != par) maxi = max(maxi, dfs(a, cur)); return maxi + 1; }; for (int i = 0; i < n; i++) { vector<int> vi; for (auto a : adjlist[i]) vi.push_back(dfs(a, i)); int ct = 0; for (auto a : vi) { if (a >= 3) ct++; } if (ct >= 2 && vi.size() >= 3) { cout << "NO\n"; return 0; } } cout << "YES\n1\n1\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...