Submission #792084

#TimeUsernameProblemLanguageResultExecution timeMemory
792084kwongwengNewspapers (CEOI21_newspapers)C++17
0 / 100
0 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define fi first #define se second vi g[1001]; vi d(1001), mxd(1001), p(1001); // mxd[u] - max d[v] for v in subtree u void dfs(int u){ for (int v : g[u]){ if (p[u]==v) continue; p[v] = u; d[v]=d[u]+1; dfs(v); mxd[u] = max(mxd[u], mxd[v]); } } void solve(){ int n, m; cin >> n >> m; FOR(i,0,m){ int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } if (m>n-1){ cout << "NO\n"; return; } FOR(u,1,n+1){ FOR(i,1,n+1){ d[i]=0; p[i]=0; mxd[i]=0; } dfs(u); int cnt = 0; for (int v : g[u]){ if (mxd[v] >= 3){ cnt++; } } if (cnt >= 3){ cout << "NO\n"; return; } } cout << "YES\n"; } int main(){ ios::sync_with_stdio(false); if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int TC = 1; //cin >> TC; FOR(i, 1, TC+1){ //cout << "Case #" << i << ": "; solve(); } return 0; }

Compilation message (stderr)

newspapers.cpp: In function 'int main()':
newspapers.cpp:63:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   freopen("input.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
newspapers.cpp:64:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   freopen("output.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...