답안 #525098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525098 2022-02-10T17:09:15 Z azberjibiou Firefighting (NOI20_firefighting) C++17
8 / 100
301 ms 30468 KB
#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=1000000;
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]=-1;
    }
}
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 << " ";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 30316 KB Output is correct
2 Correct 285 ms 30268 KB Output is correct
3 Correct 86 ms 15880 KB Output is correct
4 Correct 286 ms 29664 KB Output is correct
5 Correct 3 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7364 KB Output is correct
5 Correct 4 ms 7328 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7256 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 4 ms 7344 KB Output is correct
12 Correct 5 ms 7368 KB Output is correct
13 Correct 4 ms 7276 KB Output is correct
14 Correct 4 ms 7244 KB Output is correct
15 Correct 4 ms 7368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 30468 KB Output is correct
2 Incorrect 124 ms 20164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 241 ms 27256 KB Integer parameter [name=F] equals to 0, violates the range [1, 288940]
2 Halted 0 ms 0 KB -