QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789435#7588. Monster HunterKFCCompile Error//C++981.5kb2024-11-27 20:21:172024-11-27 20:21:18

Judging History

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

  • [2024-11-27 20:21:18]
  • 评测
  • [2024-11-27 20:21:17]
  • 提交

answer

// Hydro submission #67470ebb9592d6097b86f49e@1732710075737
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=100010;
vector<int>g[N];
int w[N],fa[N],a[N],b[N],del[N];
struct node{
	int id,a,b;
	bool operator <(const node &cmp)const{
		int f1=(b>a),f2=(cmp.b>cmp.a);
		if(f1==f2){
			if(f1==0)
				return (b==cmp.b?id>cmp.id:b>cmp.b);
			return (a==cmp.a?id>cmp.id:a<cmp.a);
		}
		return (f1==f2?id>cmp.id:f1>f2);
	}
};
set<node>st;
int find(int x){
	return (del[fa[x]]?fa[x]=find(fa[x]):fa[x]);
}
void dfs(int u,int f){
	w[u]=f;
	fa[u]=u;
	for(auto v:g[u]){
		if(v==f)continue;
		dfs(v,u);
	}
}
void solve(){
	int n;
	cin>>n;
	for(int i=2;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	a[1]=0,b[1]=0;
	for(int i=2;i<=n;i++)st.insert({i,a[i],b[i]});
	int T=n-1;
	while(T--){
		node it=*st.begin();st.erase(it);
		int id=find(w[it.id]);
		del[it.id]=1;
		if(id!=1)st.erase({id,a[id],b[id]});
		int aa=a[id];
		a[id]=max(a[id],a[id]+a[it.id]-b[id]);
		b[id]=b[id]+b[it.id]-aa-a[it.id]+a[id];
		fa[it.id]=id;
		if(id!=1)st.insert({id,a[id],b[id]});
	}
	cout<<a[1]<<'\n';
	for(int i=1;i<=n;i++)g[i].clear(),fa[i]=0,w[i]=0,del[i]=0;
	st.clear();
} 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int qwq;
	cin>>qwq;
	while(qwq--)
		solve();
	return 0;
}
/*
5
1 3
3 2
1 2
9 5
2 1
3 1
4 2
5 2
*/

Details

answer.code: In function ‘void dfs(long long int, long long int)’:
answer.code:28:18: error: ‘v’ does not name a type
   28 |         for(auto v:g[u]){
      |                  ^
answer.code:31:10: error: expected ‘;’ before ‘}’ token
   31 |         }
      |          ^
      |          ;
   32 | }
      | ~         
answer.code:32:1: error: expected primary-expression before ‘}’ token
   32 | }
      | ^
answer.code:31:10: error: expected ‘;’ before ‘}’ token
   31 |         }
      |          ^
      |          ;
   32 | }
      | ~         
answer.code:32:1: error: expected primary-expression before ‘}’ token
   32 | }
      | ^
answer.code:31:10: error: expected ‘)’ before ‘}’ token
   31 |         }
      |          ^
      |          )
   32 | }
      | ~         
answer.code:28:12: note: to match this ‘(’
   28 |         for(auto v:g[u]){
      |            ^
answer.code:32:1: error: expected primary-expression before ‘}’ token
   32 | }
      | ^
answer.code: In function ‘void solve()’:
answer.code:45:40: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   45 |         for(int i=2;i<=n;i++)st.insert({i,a[i],b[i]});
      |                                        ^
answer.code:45:39: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   45 |         for(int i=2;i<=n;i++)st.insert({i,a[i],b[i]});
      |                              ~~~~~~~~~^~~~~~~~~~~~~~~
answer.code:51:35: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   51 |                 if(id!=1)st.erase({id,a[id],b[id]});
      |                                   ^
answer.code:51:34: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   51 |                 if(id!=1)st.erase({id,a[id],b[id]});
      |                          ~~~~~~~~^~~~~~~~~~~~~~~~~~
answer.code:56:36: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   56 |                 if(id!=1)st.insert({id,a[id],b[id]});
      |                                    ^
answer.code:56:35: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   56 |                 if(id!=1)st.insert({id,a[id],b[id]});
      |                          ~~~~~~~~~^~~~~~~~~~~~~~~~~~