QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716760#9532. 长野原龙势流星群konata2828Compile Error//C++981004b2024-11-06 15:59:432024-11-06 15:59:44

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 15:59:44]
  • 评测
  • [2024-11-06 15:59:43]
  • 提交

answer

// Hydro submission #672b21eda059678966637204@1730879981852
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;

const int N = 2e5 + 5;
const double eps = 1e-9;
int n, w[N], cnt[N], ans[N];
vector<int> g[N];
priority_queue<pair<double, int> > hep[N];

void dfs(int u){
	cnt[u] = 1;
	for(int v : g[u]){
		dfs(v);
		hep[u].push(make_pair((double)(ans[v]) / cnt[v], v));}
	while(!hep[u].empty()){
		if(hep[u].top().first <= (double)(ans[u]) / cnt[u] - eps)
			break;
		int v = hep[u].top().second; hep[u].pop();
		cnt[u] += cnt[v], ans[u] += ans[v];
		if(hep[u].size() < hep[v].size()) swap(hep[u], hep[v]);
		while(!hep[v].empty()) hep[u].push(hep[v].top()), hep[v].pop();
	}
	return ;
}

signed main(){
	cin >> n;
	for(int i = 2, p; i <= n; i++)
		cin >> p, g[p].push_back(i);
	for(int i = 1; i <= n; i++) cin >> ans[i];
	
	dfs(1);
	
	for(int i = 1; i <= n; i++)
		printf("%.10Lf\n", (double)(ans[i]) / cnt[i]);
	return 0;
}

Details

answer.code: In function ‘void dfs(long long int)’:
answer.code:15:21: warning: range-based ‘for’ loops only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   15 |         for(int v : g[u]){
      |                     ^
answer.code:15:24: error: forming reference to reference type ‘std::vector<long long int>&’
   15 |         for(int v : g[u]){
      |                        ^