This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll const INF = ll(1e16);
ll n, k, x, y, z;
vector<pi> adj[300005];
vector<ll> ans;
pi dfs(ll p, ll from, ll dist)
{
ll overflow = -INF, underflow = 0;
for (pi u: adj[from])
{
if (u.f==p) continue;
pi ret = dfs(from, u.f, u.s);
if (ret.f==0) underflow = max(underflow, ret.s);
if (ret.f==1) overflow = max(overflow, ret.s);
}
pi ret;
if (overflow>=underflow) {ret = mp(1, overflow - dist);}
else
{
if (underflow+dist>k)
{
ans.pb(from);
ret = mp(1, k-dist);
}
else
{
ret = mp(0, underflow + dist);
}
}
if (ret.f && ret.s<0) ret= mp(0, 0); // reset from overflow to underflow
//show2(ret.f, ret.s);
return ret;
}
int main()
{
input(n); input(k);
for (ll i=0; i<n-1; ++i)
{
input(x); input(y); input(z);
adj[x].pb(mp(y,z));
adj[y].pb(mp(x,z));
}
dfs(-1, 1, INF);
print((ll) ans.size(), '\n');
for (ll u: ans) print(u, ' ');
printf("%c", '\n');
return 0;
}
Compilation message (stderr)
Firefighting.cpp: In function 'int main()':
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
Firefighting.cpp:65:2: note: in expansion of macro 'input'
65 | input(n); input(k);
| ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
Firefighting.cpp:65:12: note: in expansion of macro 'input'
65 | input(n); input(k);
| ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
Firefighting.cpp:68:3: note: in expansion of macro 'input'
68 | input(x); input(y); input(z);
| ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
Firefighting.cpp:68:13: note: in expansion of macro 'input'
68 | input(x); input(y); input(z);
| ^~~~~
Firefighting.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
Firefighting.cpp:68:23: note: in expansion of macro 'input'
68 | input(x); input(y); input(z);
| ^~~~~
# | 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... |