제출 #524190

#제출 시각아이디문제언어결과실행 시간메모리
524190Cross_RatioFirefighting (NOI20_firefighting)C++14
8 / 100
287 ms31804 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 == INF) { if(len == -1 || ma + len > K) { type[c] = true; ans.push_back(c); return len; } type[c] = false; return len + ma; } if(mi + ma > K) { type[c] = true; ans.push_back(c); return len; } if(mi + len <= K) { type[c] = true; return mi + len; } type[c] = false; return 0; } 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 << ' '; }

컴파일 시 표준 에러 (stderr) 메시지

Firefighting.cpp: In function 'int main()':
Firefighting.cpp:58: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]
   58 |     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...