이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |