답안 #868167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868167 2023-10-30T15:57:13 Z amirhoseinfar1385 Magic Tree (CEOI19_magictree) C++17
68 / 100
2000 ms 30176 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
vector<int>adj[maxn];
int n,m,k;
pair<int,int>allq[maxn];
set<pair<int,int>>st[maxn];

void insert(int u){
	if(allq[u].second==0){
		return ;
	}
	auto x=allq[u];
	auto y=*st[u].lower_bound(make_pair(x.first,-1));
	if(y.first==x.first){
		x.second+=y.second;
		st[u].erase(y);
	}
	st[u].insert(x);
	int z=x.first;
	while((*st[u].rbegin()).first>z){
		y=*st[u].lower_bound(make_pair(z+1,-1));
		if(y.second<allq[u].second){
			st[u].erase(y);
			allq[u].second-=y.second;
		}	
		else{
			st[u].erase(y);
			y.second-=allq[u].second;
			st[u].insert(y);
			allq[u].second=0;
			break;
		}
	}
}

void merge(int u,int v){
	int fu=u,fv=v;
	if((int)st[u].size()<(int)st[v].size()){
		swap(u,v);
	}
	for(auto x:st[v]){
		auto y=*st[u].lower_bound(make_pair(x.first,-1));
		if(y.first!=x.first){
			st[u].insert(x);
		}
		else{
			st[u].erase(y);
			y.second+=x.second;
			st[u].insert(y);
		}
	}
	if(u!=fu){
		swap(st[u],st[fu]);
	}
}

void co(int u){
	cout<<"u: "<<u<<" \n";
	for(auto x:st[u]){
		cout<<x.first<<" "<<x.second<<"\n";
	}
}

void solve(int u=1){
	if((int)adj[u].size()==0){
		insert(u);
		//co(u);
		return ;
	}
	solve(adj[u][0]);
	swap(st[u],st[adj[u][0]]);
	for(int i=1;i<(int)adj[u].size();i++){
		solve(adj[u][i]);
		merge(u,adj[u][i]);
	}
	insert(u);
	//co(u);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k;
	for(int i=2;i<=n;i++){
		int d;
		cin>>d;
		adj[d].push_back(i);
	}
	for(int i=0;i<m;i++){
		int v,d,w;
		cin>>v>>d>>w;
		allq[v]=make_pair(d,w);
	}
	solve();
	long long res=0;
	for(auto x:st[1]){
		res+=x.second;
	}
	cout<<res<<'\n';
}

Compilation message

magictree.cpp: In function 'void merge(int, int)':
magictree.cpp:38:11: warning: unused variable 'fv' [-Wunused-variable]
   38 |  int fu=u,fv=v;
      |           ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8248 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 16548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 48 ms 19576 KB Output is correct
5 Correct 53 ms 22332 KB Output is correct
6 Correct 87 ms 19844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2054 ms 11792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8248 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8288 KB Output is correct
10 Correct 57 ms 16980 KB Output is correct
11 Correct 59 ms 16016 KB Output is correct
12 Correct 47 ms 15448 KB Output is correct
13 Correct 45 ms 13780 KB Output is correct
14 Correct 56 ms 19084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 17 ms 10604 KB Output is correct
3 Correct 16 ms 10584 KB Output is correct
4 Correct 17 ms 10588 KB Output is correct
5 Correct 8 ms 8924 KB Output is correct
6 Correct 19 ms 11492 KB Output is correct
7 Correct 17 ms 13916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8248 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8288 KB Output is correct
10 Correct 2 ms 8284 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 48 ms 19576 KB Output is correct
14 Correct 53 ms 22332 KB Output is correct
15 Correct 87 ms 19844 KB Output is correct
16 Correct 57 ms 16980 KB Output is correct
17 Correct 59 ms 16016 KB Output is correct
18 Correct 47 ms 15448 KB Output is correct
19 Correct 45 ms 13780 KB Output is correct
20 Correct 56 ms 19084 KB Output is correct
21 Correct 19 ms 11356 KB Output is correct
22 Correct 61 ms 18116 KB Output is correct
23 Correct 71 ms 21176 KB Output is correct
24 Correct 124 ms 30176 KB Output is correct
25 Correct 62 ms 16852 KB Output is correct
26 Correct 83 ms 18772 KB Output is correct
27 Correct 98 ms 17492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8248 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 2 ms 8284 KB Output is correct
5 Correct 2 ms 8284 KB Output is correct
6 Correct 2 ms 8284 KB Output is correct
7 Correct 2 ms 8284 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 2 ms 8288 KB Output is correct
10 Incorrect 52 ms 16548 KB Output isn't correct
11 Halted 0 ms 0 KB -