제출 #1280709

#제출 시각아이디문제언어결과실행 시간메모리
1280709StefanSebezFireworks (APIO16_fireworks)C++20
26 / 100
118 ms3920 KiB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=5050;
const ll inf=1e18;
void chmn(ll &x,ll y){x=min(x,y);}
void chmx(ll &x,ll y){x=max(x,y);}
vector<pair<int,int>>E[N];
ll Val[N];
int n,m;
void DFS1(int u){
    for(auto [i,w]:E[u]){
        Val[i]=Val[u]+w;
        DFS1(i);
    }
}
ll dp[N][N];
void DFS(int u){
    if(E[u].empty()){
        for(int i=1;i<=n;i++) dp[u][i]=inf;
        dp[u][u]=0;
        return;
    }
    for(auto [i,w]:E[u]) DFS(i);
    for(int j=1;j<=n;j++){
        dp[u][j]=0;
        for(auto [i,w]:E[u]){
            ll mn=inf;
            for(int k=1;k<=n;k++){
                if(Val[k]-w<=Val[j]) chmn(mn,dp[i][k]+abs(Val[j]-Val[k]));
            }
            dp[u][j]+=mn;
            chmn(dp[u][j],inf);
        }
    }
}
int main(){
    scanf("%i%i",&n,&m);
    n+=m;
    for(int i=2;i<=n;i++){
        int p,w;scanf("%i%i",&p,&w);
        E[p].pb({i,w});
    }
    DFS1(1);
    DFS(1);
    ll res=inf;
    for(int i=1;i<=n;i++) chmn(res,dp[1][i]);
    printf("%lld\n",res);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

fireworks.cpp: In function 'int main()':
fireworks.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%i%i",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
fireworks.cpp:45:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         int p,w;scanf("%i%i",&p,&w);
      |                 ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...