#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 5*1e4+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll n, m;
ll t=0;
vector<pll> a[dim];
ll dp[dim][500];
int main() {
ll d, k;
cin>>n>>m>>k;
for(int i=1; i<=n-1; i++) {
for (int j = 1; j <= k; j++) {
ll u, w;
cin >> u >> w;
u++;
a[u].pb({i, w});
}
}
dp[1][0]=1;
for(int i=2; i<=n; i++){
for(auto x:a[i]){
ll val=x.se;
for(int j=0; j<=m; j++){
ll cur=min<ll>(j+val, m+1);
dp[i][cur]+=dp[x.fi][j];
dp[i][cur]=min<ll>(dp[i][cur], 5e8+1);
}
}
for(int j=0; j<=m; j++){
dp[i][j]+=dp[i][j-1];
dp[i][j]=min<ll>(dp[i][j], 5e8+1);
}
}
ll sum=0;
for(int i=0; i<=m-1; i++ ){
cout<<dp[n][i]<<" ";
}
cout<<endl;
return 0;
}
# | 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... |