Submission #1083822

#TimeUsernameProblemLanguageResultExecution timeMemory
1083822mmdrzadaBurza (COCI16_burza)C++17
0 / 160
1 ms480 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define sep ' ' #define F first #define S second #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define kill(x) {cout << x << endl;return;} const int N = 500; const ll LLINF = 2e18; const int INF = INT_MAX/2; int n, k; int h[N]; int par[N]; int cnt[N]; vi adj[N]; ll dp[N]; ll pf[N]; // check MAXN // diffrence between extract and erase in multi set void set_io() { fastIO; // freopen("guard.in", "r", stdin); // freopen("guard.out", "w", stdout); } void dfs(int v = 0, int p = -1) { h[v] = (p == -1 ? 0 : h[p] + 1); par[v] = p; if (h[v] == k) { // dp base dp[v] = INF; return; } if (adj[v].size() == 1 && adj[v][0] == p) { dp[v] = 0; return; } int k = 0; for(int i = 0 ; i < adj[v].size(); i ++) { int neigh = adj[v][i]; if (neigh == p) { pf[i] = k; continue; } dfs(neigh, v); pf[i] = k; k += dp[neigh]; } k = 0; ll ans = INF; for(int i = adj[v].size()-1 ; i >= 0 ; i --) { int neigh = adj[v][i]; if (neigh == p) continue; ans = min(ans, pf[i] + 1ll + k); k += dp[neigh]; } dp[v] = ans; } void solve() { cin >> n >> k; for(int i = 0, a, b ; i < n-1 ; i ++) cin >> a >> b, adj[--a].pb(--b), adj[b].pb(a); dfs(); cout << (dp[0] <= k ? "DA" : "NE") << endl; } int main() { set_io(); solve(); return 0; }

Compilation message (stderr)

burza.cpp: In function 'void dfs(int, int)':
burza.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i = 0 ; i < adj[v].size(); i ++) {
      |                  ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...