이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define NAME ""
#define ll long long
#define pii pair < int , int >
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i ++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i --)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i ++)
#define bit(x, i) (((x) >> (i)) & 1ll)
#define mask(x) (1ll << (x))
#define mem(f, x) memset(f, x, sizeof(f))
#define sz(x) (int32_t) (x.size())
const int nmax = 1e5;
int lim;
pii fruit[nmax + 5];
vector < int > adj[nmax + 5];
vector < vector < ll > > dp;
void dfs(int i) {
for (auto x: adj[i]) {
dfs(x);
ll cur = 0;
FOR(j, 0, lim) {
cur = max(cur, dp[x][j]);
dp[i][j] += cur;
}
}
dp[i][fruit[i].fi] += fruit[i].se;
// cout << i << ":\n";
// FOR(j, 1, lim) {
// cout << j << " " << dp[i][j] << "\n";
// }
}
signed main() {
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".ans", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m >> lim;
if (n * lim > (int)1e7) {
return 0;
}
dp.assign(n + 1, vector < ll > (lim + 1, 0));
FOR(i, 2, n) {
int p;
cin >> p;
adj[p].push_back(i);
}
for (; m --;) {
int v, d, w;
cin >> v >> d >> w;
fruit[v] = {d, w};
}
dfs(1);
ll ans = 0;
FORD(j, lim, 0) {
ans = max(ans, dp[1][j]);
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
magictree.cpp: In function 'int main()':
magictree.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen(NAME".ans", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | 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... |