Submission #647249

# Submission time Handle Problem Language Result Execution time Memory
647249 2022-10-02T04:01:23 Z atom Fireworks (APIO16_fireworks) Java 11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;    
const int N=300010, M = 1e9 + 7;

int n,m,a,b,plague[N],root[N],ans;

vector<int> edges[N];

priority_queue<int> q[N];

void dfs(int v){

	root[v]=v;

	if(v>n){

		q[v].push(plague[v]); q[v].push(plague[v]);

		return;

	}

	for(auto i:edges[v]){

		dfs(i);

		if(q[root[i]].size() > q[root[v]].size()) root[v]=root[i];

	}

	for(auto i:edges[v]) if(root[i]!=root[v]){

		while(q[root[i]].size()){

			q[root[v]].push(q[root[i]].top()); 
			q[root[i]].pop();

		}

	}
	for (int i = 1; i < (int) edges[v].size(); i++) q[root[v]].pop();

	a=q[root[v]].top(); q[root[v]].pop(); b=q[root[v]].top(); q[root[v]].pop();

	a+=plague[v]; b+=plague[v]; q[root[v]].push(b); q[root[v]].push(a);

}


int main(){

	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n >> m;
	m += n;
	for (int i = 2; i <= m; i++){

		cin>>a>>b;

		edges[a].push_back(i);

		plague[i]=b; ans+=b;

	}

	dfs(1);

	q[root[1]].pop(); 
	a=q[root[1]].top(); 
	q[root[1]].push(0); 
	b=0;

	while(q[root[1]].size() > 0){

		ans-=(a - q[root[1]].top()) * b;
		b++;
		a=q[root[1]].top(); 
		q[root[1]].pop();

	}

	cout<<ans << "\n";

	return 0;

}

Compilation message

fireworks.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
fireworks.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
fireworks.java:3: error: class, interface, or enum expected
using ll = long long;    
^
fireworks.java:4: error: class, interface, or enum expected
const int N=300010, M = 1e9 + 7;
^
fireworks.java:6: error: class, interface, or enum expected
int n,m,a,b,plague[N],root[N],ans;
^
fireworks.java:8: error: class, interface, or enum expected
vector<int> edges[N];
^
fireworks.java:10: error: class, interface, or enum expected
priority_queue<int> q[N];
^
fireworks.java:12: error: class, interface, or enum expected
void dfs(int v){
^
fireworks.java:16: error: class, interface, or enum expected
	if(v>n){
	^
fireworks.java:18: error: class, interface, or enum expected
		q[v].push(plague[v]); q[v].push(plague[v]);
		                      ^
fireworks.java:20: error: class, interface, or enum expected
		return;
		^
fireworks.java:22: error: class, interface, or enum expected
	}
	^
fireworks.java:28: error: class, interface, or enum expected
		if(q[root[i]].size() > q[root[v]].size()) root[v]=root[i];
		^
fireworks.java:30: error: class, interface, or enum expected
	}
	^
fireworks.java:37: error: class, interface, or enum expected
			q[root[i]].pop();
			^
fireworks.java:39: error: class, interface, or enum expected
		}
		^
fireworks.java:42: error: class, interface, or enum expected
	for (int i = 1; i < (int) edges[v].size(); i++) q[root[v]].pop();
	                ^
fireworks.java:42: error: class, interface, or enum expected
	for (int i = 1; i < (int) edges[v].size(); i++) q[root[v]].pop();
	                                           ^
fireworks.java:44: error: class, interface, or enum expected
	a=q[root[v]].top(); q[root[v]].pop(); b=q[root[v]].top(); q[root[v]].pop();
	^
fireworks.java:44: error: class, interface, or enum expected
	a=q[root[v]].top(); q[root[v]].pop(); b=q[root[v]].top(); q[root[v]].pop();
	                    ^
fireworks.java:44: error: class, interface, or enum expected
	a=q[root[v]].top(); q[root[v]].pop(); b=q[root[v]].top(); q[root[v]].pop();
	                                      ^
fireworks.java:44: error: class, interface, or enum expected
	a=q[root[v]].top(); q[root[v]].pop(); b=q[root[v]].top(); q[root[v]].pop();
	                                                          ^
fireworks.java:46: error: class, interface, or enum expected
	a+=plague[v]; b+=plague[v]; q[root[v]].push(b); q[root[v]].push(a);
	^
fireworks.java:46: error: class, interface, or enum expected
	a+=plague[v]; b+=plague[v]; q[root[v]].push(b); q[root[v]].push(a);
	              ^
fireworks.java:46: error: class, interface, or enum expected
	a+=plague[v]; b+=plague[v]; q[root[v]].push(b); q[root[v]].push(a);
	                            ^
fireworks.java:46: error: class, interface, or enum expected
	a+=plague[v]; b+=plague[v]; q[root[v]].push(b); q[root[v]].push(a);
	                                                ^
fireworks.java:48: error: class, interface, or enum expected
}
^
fireworks.java:53: error: class, interface, or enum expected
	ios_base::sync_with_stdio(0); cin.tie(0);
	                              ^
fireworks.java:55: error: class, interface, or enum expected
	cin >> n >> m;
	^
fireworks.java:56: error: class, interface, or enum expected
	m += n;
	^
fireworks.java:57: error: class, interface, or enum expected
	for (int i = 2; i <= m; i++){
	^
fireworks.java:57: error: class, interface, or enum expected
	for (int i = 2; i <= m; i++){
	                ^
fireworks.java:57: error: class, interface, or enum expected
	for (int i = 2; i <= m; i++){
	                        ^
fireworks.java:61: error: class, interface, or enum expected
		edges[a].push_back(i);
		^
fireworks.java:63: error: class, interface, or enum expected
		plague[i]=b; ans+=b;
		^
fireworks.java:63: error: class, interface, or enum expected
		plague[i]=b; ans+=b;
		             ^
fireworks.java:65: error: class, interface, or enum expected
	}
	^
fireworks.java:69: error: class, interface, or enum expected
	q[root[1]].pop(); 
	^
fireworks.java:70: error: class, interface, or enum expected
	a=q[root[1]].top(); 
	^
fireworks.java:71: error: class, interface, or enum expected
	q[root[1]].push(0); 
	^
fireworks.java:72: error: class, interface, or enum expected
	b=0;
	^
fireworks.java:74: error: class, interface, or enum expected
	while(q[root[1]].size() > 0){
	^
fireworks.java:77: error: class, interface, or enum expected
		b++;
		^
fireworks.java:78: error: class, interface, or enum expected
		a=q[root[1]].top(); 
		^
fireworks.java:79: error: class, interface, or enum expected
		q[root[1]].pop();
		^
fireworks.java:81: error: class, interface, or enum expected
	}
	^
fireworks.java:85: error: class, interface, or enum expected
	return 0;
	^
fireworks.java:87: error: class, interface, or enum expected
}
^
48 errors