Submission #524202

#TimeUsernameProblemLanguageResultExecution timeMemory
524202Cross_RatioFirefighting (NOI20_firefighting)C++14
100 / 100
276 ms44328 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int INF = 1e18; typedef pair<int,int> P; vector<vector<P>> adj; bool type[300005]; vector<int> ans; int K; int dfs(int c, int p, int len) { int ma = 0, mi = INF; for(P n2 : adj[c]) { int n = n2.first; int d = n2.second; if(n==p) continue; int l = dfs(n, c, d); if(type[n]) mi = min(mi, l); // sobang case else ma = max(ma, l); } //cout << c << ' ' <<ma << ' ' << mi << '\n'; if(mi + ma > K) { if(len == -1 || ma + len > K) { type[c] = true; ans.push_back(c); return len; } type[c] = false; return len + ma; } if(mi+len > K) { type[c] = false; return 0; } type[c] = true; return len + mi; } signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N >> K; int i; adj.resize(N); for(i=0;i<N-1;i++) { int a, b, c; cin >> a >> b >>c; adj[a-1].push_back(P(b-1, c)); adj[b-1].push_back(P(a-1, c)); } dfs(0, -1, -1); cout << ans.size() << '\n'; for(i=0;i<ans.size();i++) cout << ans[i] + 1 << ' '; }

Compilation message (stderr)

Firefighting.cpp: In function 'int main()':
Firefighting.cpp:53:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(i=0;i<ans.size();i++) cout << ans[i] + 1 << ' ';
      |             ~^~~~~~~~~~~
#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...