UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211838#3807. 随机游走drdilyorCompile Error//C++1.4kb2024-10-07 14:55:472024-10-29 10:32:10

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int n;
int fa[500005],v[500005];
vector<pair<int,int>> e[500005];
int w[500005];
int cs[500005],tw[500005];
int res;
void dfs_init(int x){
	tw[x]=w[x];
	for(int i=0;i<(int)e[x].size();i++){
		int v=e[x][i].first,w=e[x][i].second;
		cs[x]+=w;
		dfs_init(v);
		cs[x]+=cs[v];
		tw[x]+=tw[v];
	}
}
bool cmp(pair<int,int> p,pair<int,int> q){
	int v1=p.first,v2=q.first,w1=p.second,w2=q.second;
	return (cs[v1]+w1)*tw[v2]<(cs[v2]+w2)*tw[v1];
}
void dfs(int x,int c){
	//cout<<"trav "<<x<<" "<<c<<"\n";
	res+=w[x]*c;
	if(e[x].empty())return;
	vector<pair<int,int>> son;
	for(int i=0;i<(int)e[x].size();i++){
		son.push_back(e[x][i]);
	}
	sort(son.begin(),son.end(),cmp);
	for(int i=0;i<(int)son.size();i++){
		int v=son[i].first,w=son[i].second;
		dfs(v,c+w);
		c+=cs[v]+w;
	}
	//走 v1 v2.
	//cs/tw 的值最大.
	//+(c+w1)*(tw[v1])+(c+cs[v1]+w1+w2)*tw[v2]
	//+(c+w2)*tw[v2]+(c+cs[v2]+w2+w1)*tw[v1]
}
signed main(){
	n=read();
	for(int i=2;i<=n;i++)fa[i]=read(),v[i]=read(),e[fa[i]].push_back(make_pair(i,v[i]));
	for(int i=1;i<=n;i++)w[i]=read();
	dfs_init(1);
	dfs(1,0);
	cout<<res<<"\n";
	return 0;
}
//look at my code
//my code is amazing

详细

answer.code:19:20: error: '>>' should be '> >' within a nested template argument list
 vector<pair<int,int>> e[500005];\x0d
                    ^
answer.code: In function 'void dfs(long long int, long long int)':
answer.code:41:21: error: '>>' should be '> >' within a nested template argument list
  vector<pair<int,int>> son;\x0d
                     ^