Submission #896247

# Submission time Handle Problem Language Result Execution time Memory
896247 2024-01-01T05:17:11 Z 8pete8 Magic Tree (CEOI19_magictree) C++17
58 / 100
119 ms 153936 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<float.h>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
#define double long double
const int mod=998244353,mxn=1e6,lg=22;//inf=1e18,minf=-1e18,Mxn=100000;
vector<int>adj[mxn+10];
map<int,int>mp[mxn+10];
pii info[mxn+10];
int n,m,k;
ll ans=0;
void dfs2(int cur,int p){
	for(auto i:adj[cur]){
		dfs2(i,cur);
		if(mp[i].size()>mp[cur].size())swap(mp[cur],mp[i]);
		for(auto j:mp[i])mp[cur][j.f]+=j.s;
	}
	mp[cur][info[cur].f]+=info[cur].s;
	auto it=mp[cur].upper_bound(info[cur].f);
	while(it!=mp[cur].end()&&info[cur].s){
		if(it==mp[cur].end())assert(0);
		if(info[cur].s>=it->s)info[cur].s-=it->s,mp[cur].erase(it);
		else it->s-=info[cur].s,info[cur].s=0;
	}
}
int32_t main(){
    fastio
	cin>>n>>m>>k;
	for(int i=2;i<=n;i++){
		int p;cin>>p;
		adj[p].pb(i);
	}
	bool yes=true;
	for(int i=0;i<m;i++){
		int v,d,w;cin>>v>>d>>w;
		info[v]={d,w};
	}
	ans=0;
	dfs2(1,-1);
	for(auto i:mp[1])ans+=i.s;
	cout<<ans;
	return 0;
}

Compilation message

magictree.cpp: In function 'int32_t main()':
magictree.cpp:64:7: warning: unused variable 'yes' [-Wunused-variable]
   64 |  bool yes=true;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 71772 KB Output is correct
2 Correct 16 ms 72028 KB Output is correct
3 Correct 15 ms 72020 KB Output is correct
4 Correct 15 ms 71768 KB Output is correct
5 Correct 14 ms 71772 KB Output is correct
6 Correct 15 ms 71768 KB Output is correct
7 Correct 15 ms 72028 KB Output is correct
8 Correct 15 ms 72024 KB Output is correct
9 Correct 15 ms 71772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 86356 KB Output is correct
2 Correct 46 ms 85072 KB Output is correct
3 Correct 119 ms 101432 KB Output is correct
4 Correct 70 ms 84936 KB Output is correct
5 Correct 95 ms 86100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 72028 KB Output is correct
2 Correct 15 ms 72028 KB Output is correct
3 Correct 16 ms 72028 KB Output is correct
4 Correct 51 ms 91436 KB Output is correct
5 Correct 69 ms 95296 KB Output is correct
6 Correct 63 ms 91476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 153936 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 71772 KB Output is correct
2 Correct 16 ms 72028 KB Output is correct
3 Correct 15 ms 72020 KB Output is correct
4 Correct 15 ms 71768 KB Output is correct
5 Correct 14 ms 71772 KB Output is correct
6 Correct 15 ms 71768 KB Output is correct
7 Correct 15 ms 72028 KB Output is correct
8 Correct 15 ms 72024 KB Output is correct
9 Correct 15 ms 71772 KB Output is correct
10 Correct 68 ms 83388 KB Output is correct
11 Correct 61 ms 82256 KB Output is correct
12 Correct 52 ms 83460 KB Output is correct
13 Correct 52 ms 81168 KB Output is correct
14 Correct 50 ms 91224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 150868 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 71772 KB Output is correct
2 Correct 16 ms 72028 KB Output is correct
3 Correct 15 ms 72020 KB Output is correct
4 Correct 15 ms 71768 KB Output is correct
5 Correct 14 ms 71772 KB Output is correct
6 Correct 15 ms 71768 KB Output is correct
7 Correct 15 ms 72028 KB Output is correct
8 Correct 15 ms 72024 KB Output is correct
9 Correct 15 ms 71772 KB Output is correct
10 Correct 15 ms 72028 KB Output is correct
11 Correct 15 ms 72028 KB Output is correct
12 Correct 16 ms 72028 KB Output is correct
13 Correct 51 ms 91436 KB Output is correct
14 Correct 69 ms 95296 KB Output is correct
15 Correct 63 ms 91476 KB Output is correct
16 Correct 68 ms 83388 KB Output is correct
17 Correct 61 ms 82256 KB Output is correct
18 Correct 52 ms 83460 KB Output is correct
19 Correct 52 ms 81168 KB Output is correct
20 Correct 50 ms 91224 KB Output is correct
21 Correct 29 ms 77148 KB Output is correct
22 Correct 74 ms 86100 KB Output is correct
23 Correct 89 ms 89656 KB Output is correct
24 Correct 110 ms 95568 KB Output is correct
25 Correct 65 ms 84876 KB Output is correct
26 Correct 85 ms 86364 KB Output is correct
27 Correct 69 ms 85224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 71772 KB Output is correct
2 Correct 16 ms 72028 KB Output is correct
3 Correct 15 ms 72020 KB Output is correct
4 Correct 15 ms 71768 KB Output is correct
5 Correct 14 ms 71772 KB Output is correct
6 Correct 15 ms 71768 KB Output is correct
7 Correct 15 ms 72028 KB Output is correct
8 Correct 15 ms 72024 KB Output is correct
9 Correct 15 ms 71772 KB Output is correct
10 Correct 66 ms 86356 KB Output is correct
11 Correct 46 ms 85072 KB Output is correct
12 Correct 119 ms 101432 KB Output is correct
13 Correct 70 ms 84936 KB Output is correct
14 Correct 95 ms 86100 KB Output is correct
15 Correct 15 ms 72028 KB Output is correct
16 Correct 15 ms 72028 KB Output is correct
17 Correct 16 ms 72028 KB Output is correct
18 Correct 51 ms 91436 KB Output is correct
19 Correct 69 ms 95296 KB Output is correct
20 Correct 63 ms 91476 KB Output is correct
21 Runtime error 98 ms 153936 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -