이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cerr<<#x << " : " << x << "\n";
using namespace std ;
const int maxn = 4e5 + 10 , mod = 1e9 + 7 , inf =1e14 ;
int pr[maxn] , ted[maxn] ;
vector <int> G[maxn] ;
int W[maxn] ;
priority_queue <int> q[maxn] ;
int N, M;
void dfs(int v) {
if(v<N) {
for(int u:G[v]) {
dfs(u);
if(q[v].size()<q[u].size()) swap(q[v], q[u]);
while(q[u].size()) q[v].push(q[u].top()), q[u].pop();
}
rep(j, 1, G[v].size()-1) q[v].pop();
int x=q[v].top()+W[v]; q[v].pop();
int y=q[v].top()+W[v]; q[v].pop();
q[v].push(x), q[v].push(y);
} else q[v].push(W[v]), q[v].push(W[v]);
}
signed main(){
ios::sync_with_stdio(0) ;cin.tie(0);
int r=0;
cin>>N>>M;
rep(i, 1, N+M-1) {
int j;
cin>>j>>W[i];
G[j-1].pb(i);
r+=W[i];
}
dfs(0);
int p=q[0].top(), k=0; q[0].pop();
while(q[0].size()){
r-=k++*(p-q[0].top()), p=q[0].top(), q[0].pop();
}
cout<<r-k*p;
}
컴파일 시 표준 에러 (stderr) 메시지
fireworks.cpp: In function 'void dfs(long long int)':
fireworks.cpp:12:38: 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]
12 | #define rep(i , a , b) for(int i=a;i <= (b);i++)
| ^
fireworks.cpp:30:3: note: in expansion of macro 'rep'
30 | rep(j, 1, G[v].size()-1) q[v].pop();
| ^~~
# | 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... |