이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int n, m, k;
vector<int>P, Order;
vector<array<int, 2>>Q;
vector<vector<int>>A;
vector<vector<int>>dp;
void pre(){
P.clear(), Order.clear(), Q.clear(), A.clear(), dp.clear();
P.resize(n+1), Q.resize(n+1), A.resize(n+1), dp.resize(n+1, vector<int>(k+1));
}
void dfs(int u){
for(int i=0;i<A[u].size();i++){
int v=A[u][i];
if(v!=P[u])
dfs(v);
}
Order.push_back(u);
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m>>k;
pre();
for(int i=2;i<=n;i++){
cin>>P[i];
int u=i, v=P[i];
A[u].push_back(v);
A[v].push_back(u);
}
for(int j=0;j<m;j++){
int v, d, c;
cin>>v>>d>>c;
Q[v]={d, c};
}
dfs(1);
for(int kk=0;kk<n;kk++){
int u=Order[kk];
for(auto v:A[u]){
if(v==P[u])
continue;
for(int i=1;i<=k;i++){
dp[u][i]+=dp[v][i];
}
}
if(Q[u][0]){
dp[u][Q[u][0]]+=Q[u][1];
for(int i=Q[u][0]+1;i<=k;i++){
if(dp[u][i]>=dp[u][Q[u][0]])
break;
dp[u][i]=dp[u][i-1];
}
}
}
int ans=dp[1][k];
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:21:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<A[u].size();i++){
| ~^~~~~~~~~~~~
# | 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... |