이 제출은 이전 버전의 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 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 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... |