Submission #7679268


Source Code Expand

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
priority_queue<pair<int,pair<int,int> > > heap;
const int MAXN=3e5+7;
int n,m,ccnt;
int home[MAXN],next[MAXN],to[MAXN],f[MAXN],arr[MAXN],vis[MAXN],nxtn[MAXN];

inline void cuntu(int x,int y) {
	ccnt++;
	next[ccnt]=home[x];
	home[x]=ccnt;
	to[ccnt]=y;
	return ;
}

inline void ct(int x,int y) {
	cuntu(x,y);
	cuntu(y,x);
	return ;
}

inline void dfs(int u,int fa) {
	f[u]=fa;
	for(int i=home[u]; i; i=next[i]) {
		int v=to[i];
		if(v==fa)continue;
		dfs(v,u);
	}
	return ;
}
//把y的顺序压进x中

inline void push(int x,int y) {
	nxtn[last[x]]=y;
	last[x]=last[y];
}

inline void Init() {
	memset(home,0,sizeof(home));
	while(!heap.empty())heap.pop();
	memset(vis,0,sizeof(vis));
	memset(nxtn,0,sizeof(nxtn));
	for(int i=1; i<=n; i++)last[i]=i;
}

inline void solve() {
	while(heap.size()>1) {
		
	}
}

int main() {
	while(scanf("%d%d",&n,&m)) {
		if(n==0&&m==0)return 0;
		Init();
		for(register int i=1; i<=n; i++) {
			scanf("%d",&arr[i]);
			heap.push(make_pair(arr[i],make_pair(1,i)));
		}
		for(register int i=1,x,y; i<n; i++) {
			scanf("%d%d",&x,&y);
			ct(x,y);
		}
		dfs(1,0);
		int ans=0;
		solve();
		for(register int i=1; i<=n; i++)if(nxtn[i]==0)pos=i,qwq=last[i];
		for(register int cnt=1; pos!=qwq; pos=nxtn[pos],cnt++) {
			ans+=cnt*arr[pos];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Submission Info

Submission Time
Task D - 道路網
User luogu_bot2
Language C++ (GCC 5.4.1)
Score 0
Code Size 1416 Byte
Status CE

Compile Error

./Main.cpp: In function ‘void push(int, int)’:
./Main.cpp:38:7: error: ‘last’ was not declared in this scope
  nxtn[last[x]]=y;
       ^
./Main.cpp: In function ‘void Init()’:
./Main.cpp:47:25: error: ‘last’ was not declared in this scope
  for(int i=1; i<=n; i++)last[i]=i;
                         ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:71:49: error: ‘pos’ was not declared in this scope
   for(register int i=1; i<=n; i++)if(nxtn[i]==0)pos=i,qwq=last[i];
                                                 ^
./Main.cpp:71:55: error: ‘qwq’ was not declared in this scope
   for(register int i=1; i<=n; i++)if(nxtn[i]==0)pos=i,qwq=last[i];
                                                       ^
./Main.cpp:71:59: error: ‘last’ was not declared in this scope
   for(register int i=1; i<=n; i++)if(nxtn[i]==0)pos=i,qwq=last[i];
                                                           ^
./Main.cpp:72:27: error: ‘pos’ was not declared in this scope
   for(register int cnt=1; pos!=qwq; pos=nxtn[pos],cnt++) {
  ...