This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://oj.uz/problem/view/NOI18_journey
//
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
#define FOR(i, a, b) for (int i = (a); i<b; i++)
const int N = 1e4;
const int D = 404;
vpii adj[N];
int in[N];
int dp[N][D];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, h;
cin >> n >> m >> h;
FOR(i, 0, n - 1) {
FOR(j, 0, h) {
int w, c;
cin >> c >> w;
if (c < i) continue;
adj[i].pb({c, w});
in[c]++;
// cout << i << c << w << endl;
}
}
queue<int> q;
q.push(0);
dp[0][0]=1;
while (!q.empty()) {
auto cur = q.front();
q.pop();
// cout << cur << endl;
for (auto val: adj[cur]) {
int nxt, wt;
tie(nxt, wt) = val;
int cur_sum = 0;
for (int i = 0; i + wt <= m; i++) {
cur_sum += dp[cur][i];
dp[nxt][i + wt] = min(dp[nxt][i + wt] + cur_sum, (int) 5e8 + 1);
}
in[nxt]--;
if (in[nxt] == 0) q.push(nxt);
}
}
FOR(i, 0, m) cout << dp[n-1][i] << ' ';
cout << endl;
}
# | 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... |