제출 #524171

#제출 시각아이디문제언어결과실행 시간메모리
524171Cross_RatioFirefighting (NOI20_firefighting)C++14
3 / 100
260 ms28124 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 m1 = 0, m2 = -INF, mi = INF; for(P n2 : adj[c]) { int n = n2.first; int d = n2.second; if(n==p) continue; int len = dfs(n, c, d); if(type[n]) mi = min(mi, len); // sobang case else { if(len > m1) { m2 = m1; m1 = len; } else if(len > m2) m2 = len; } } if(mi == INF) { if(len == -1 || m1 + len > K || m1 + m2 > K) { type[c] = true; ans.push_back(c); return len; } type[c] = false; return len + m1; } if(mi + m1 > K) { type[c] = true; ans.push_back(c); return len; } if(mi + len <= K) { type[c] = true; return mi + len; } type[c] = false; return len; } 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:63: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]
   63 |     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...