Submission #1067401

#TimeUsernameProblemLanguageResultExecution timeMemory
1067401AndreyNewspapers (CEOI21_newspapers)C++14
4 / 100
1 ms1112 KiB
#include<bits/stdc++.h> using namespace std; vector<int> haha[10000]; vector<int> wow(0); vector<int> wut(0); int n,m; void dfs(int a, int t, int d) { if(d%2) { wow.push_back(a); } else { wut.push_back(a); } for(int v: haha[a]) { if(v != t) { dfs(v,a,d+1); } } } bool check() { vector<int> br(n+1); vector<int> br1(n+1); for(int i = 1; i <= n; i++) { br[i] = haha[i].size(); } for(int a: wow) { if(haha[a].size() == 1) { br[haha[a][0]]--; br[a] = -1; } } for(int i = 1; i <= n; i++) { br1[i] = br[i]; } for(int i = 1; i <= n; i++) { if(br1[i] == 1) { for(int v: haha[i]) { br[v]--; } br[i] = -1; } } for(int i = 1; i <= n; i++) { if(br[i] > 2) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; int a,b; for(int i = 0; i < m; i++) { cin >> a >> b; haha[a].push_back(b); haha[b].push_back(a); } if(m > n-1) { cout << "NO" << endl; return 0; } dfs(1,-1,0); if(check()) { cout << "YES" << endl; cout << 1 << endl << 1 << endl; } else { swap(wow,wut); if(check()) { cout << "YES" << endl; cout << 1 << endl << 1 << endl; } else { cout << "NO" << endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...