Submission #698447

# Submission time Handle Problem Language Result Execution time Memory
698447 2023-02-13T13:34:06 Z vjudge1 Fireworks (APIO16_fireworks) C++17
7 / 100
50 ms 70780 KB
    #include<bits/stdc++.h>
    #define maxn 1000000
    using namespace std;
    int n,m;
    vector<int> a[maxn];
    int p[maxn];
    int c[maxn];
    long long ans;
    multiset<long long> x[maxn];
    long long t[maxn];
    int pt[maxn];
    vector<long long> cur;
    void dfs(int u) {
    	if(a[u].size()==0) {
    		x[u].insert(c[u]);
    		x[u].insert(c[u]);
    		pt[u]=u;
    		t[u]=c[u];
    		return;
    	}
    	for(auto v:a[u]) {
    		dfs(v);
    	}
    	pt[u]=0;
    	for(auto v:a[u]) {
    		if(x[pt[v]].size()>x[pt[u]].size()) {
    			pt[u]=pt[v];
    		}
    	}
    	for(auto v:a[u]) {
    		if(pt[u]!=pt[v]) {
    			for(auto c:x[pt[v]]) {
    				x[pt[u]].insert(c);
    			}
    		}
    	}
    	int sz=a[u].size();
    	long long sum=0;
    	for(int i=0;i<sz-1;i++) {
    		sum+=(*x[pt[u]].rbegin());
    		x[pt[u]].erase(--x[pt[u]].end());
    	}
    	long long p1=(*x[pt[u]].rbegin());
    	x[pt[u]].erase(--x[pt[u]].end());
    	long long p2=(*x[pt[u]].rbegin());
    	x[pt[u]].insert(p1+c[u]);
    	x[pt[u]].insert(p2+c[u]);
    	t[u]=p1+c[u];
    	ans+=(sum-(sz-1)*p1);
    	for(auto v:a[u]) {
    		ans+=(p1-t[v]);
    	}
    }
    int main() {
    	scanf("%d %d",&n,&m);
    	for(int i=2;i<=n+m;i++) {
    		scanf("%d %d",&p[i],&c[i]);
    		a[p[i]].push_back(i);
    	}
    	dfs(1);
    	printf("%lld\n",ans);
    	return 0;
    }

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:55:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |      scanf("%d %d",&n,&m);
      |      ~~~~~^~~~~~~~~~~~~~~
fireworks.cpp:57:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |       scanf("%d %d",&p[i],&c[i]);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 34 ms 70724 KB Output is correct
3 Correct 40 ms 70780 KB Output is correct
4 Correct 35 ms 70748 KB Output is correct
5 Correct 37 ms 70760 KB Output is correct
6 Correct 32 ms 70732 KB Output is correct
7 Correct 33 ms 70700 KB Output is correct
8 Correct 32 ms 70668 KB Output is correct
9 Correct 32 ms 70764 KB Output is correct
10 Correct 33 ms 70740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70672 KB Output is correct
2 Correct 37 ms 70740 KB Output is correct
3 Incorrect 50 ms 70680 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 34 ms 70724 KB Output is correct
3 Correct 40 ms 70780 KB Output is correct
4 Correct 35 ms 70748 KB Output is correct
5 Correct 37 ms 70760 KB Output is correct
6 Correct 32 ms 70732 KB Output is correct
7 Correct 33 ms 70700 KB Output is correct
8 Correct 32 ms 70668 KB Output is correct
9 Correct 32 ms 70764 KB Output is correct
10 Correct 33 ms 70740 KB Output is correct
11 Correct 32 ms 70672 KB Output is correct
12 Correct 37 ms 70740 KB Output is correct
13 Incorrect 50 ms 70680 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 34 ms 70724 KB Output is correct
3 Correct 40 ms 70780 KB Output is correct
4 Correct 35 ms 70748 KB Output is correct
5 Correct 37 ms 70760 KB Output is correct
6 Correct 32 ms 70732 KB Output is correct
7 Correct 33 ms 70700 KB Output is correct
8 Correct 32 ms 70668 KB Output is correct
9 Correct 32 ms 70764 KB Output is correct
10 Correct 33 ms 70740 KB Output is correct
11 Correct 32 ms 70672 KB Output is correct
12 Correct 37 ms 70740 KB Output is correct
13 Incorrect 50 ms 70680 KB Output isn't correct
14 Halted 0 ms 0 KB -