Submission #525100

#TimeUsernameProblemLanguageResultExecution timeMemory
525100azberjibiouFirefighting (NOI20_firefighting)C++17
100 / 100
321 ms53024 KiB
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<double, double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pmax pair<__int128, __int128>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0};
const int mxN=300005;
const int mxM=1010;
const int mxK=105;
const int MOD=1000000007;
const ll INF=1e18;
const ll P1=1000000009;
const ll P2=1000000009;
int N;
ll K;
ll station[mxN];
ll town[mxN];
bool Chk[mxN];
vector <pll> v[mxN];
int ans;
void dfs(int now, int pre, ll dis)
{
    station[now]=INF;
    town[now]=0;
    for(pll nxt : v[now])   if(nxt.fir!=pre)
    {
        dfs(nxt.fir, now, nxt.sec);
        station[now]=min(station[now], station[nxt.fir]+nxt.sec);
        town[now]=max(town[now], town[nxt.fir]+nxt.sec);
    }
    if(now==1)
    {
        if(town[now]>K-station[now])
        {
            Chk[now]=true;
            ans++;
        }
        return;
    }
    if(town[now]<=K-station[now])   town[now]=-INF;
    if(town[now]+dis>K)
    {
        Chk[now]=true;
        ans++;
        station[now]=0;
        town[now]=-INF;
    }
}
int main()
{
    gibon
    cin >> N >> K;
    for(int i=1;i<N;i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        v[a].emplace_back(b, c);
        v[b].emplace_back(a, c);
    }
    dfs(1, -1, 0);
    cout << ans << '\n';
    for(int i=1;i<=N;i++)
    {
        if(Chk[i])  cout << i << " ";
    }
}
#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...