QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788682#7588. Monster Hunterkonata2828Compile Error//C++981.2kb2024-11-27 17:53:052024-11-27 17:53:05

Judging History

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

  • [2024-11-27 17:53:05]
  • 评测
  • [2024-11-27 17:53:05]
  • 提交

answer

// Hydro submission #6746ebff9592d6097b86a432@1732701183326
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[100010],b[100010],p[100010],fa[100010];
vector<int> g[100010];
struct Node{
    int u,a,b;
    friend bool operator<(Node x,Node y)
	{
        if((x.a<x.b)!=(y.a<y.b))return y.a<y.b;
        return x.a<x.b?x.a>y.a:x.b<y.b;
    }
};
priority_queue<Node> pq;
void dfs(int u,int fat)
{
    fa[u]=fat;
    for(int v:g[u])if(v!=fat)dfs(v,u);
}
int find(int x)
{
    if(p[x]!=x)p[x]=find(p[x]);
    return p[x];
}
void solve()
{
    int i;
    cin>>n;
    for(i=1;i<=n;i++)p[i]=i,g[i].clear();
    for(i=2;i<=n;i++)cin>>a[i]>>b[i];
    for(i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b),g[b].push_back(a);
    }
    dfs(1,0);
    for(i=2;i<=n;i++)pq.push({i,a[i],b[i]});
    while(pq.size()){
        Node x=pq.top();
		pq.pop();
        if(x.u==1||a[x.u]!=x.a||b[x.u]!=x.b||find(x.u)!=x.u)continue;
        int u=x.u,v=find(fa[u]),c=max(a[v],a[u]+a[v]-b[v]),d=c-a[u]+b[u]-a[v]+b[v];
        p[u]=v,a[v]=c,b[v]=d,pq.push({v,a[v],b[v]});
    }
    cout<<a[1]<<'\n';
}
signed main()
{
	int _;cin>>_;
	while(_--)solve();
}

Details

answer.code: In function ‘void dfs(long long int, long long int)’:
answer.code:20:15: warning: range-based ‘for’ loops only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   20 |     for(int v:g[u])if(v!=fat)dfs(v,u);
      |               ^
answer.code:20:18: error: forming reference to reference type ‘std::vector<long long int>&’
   20 |     for(int v:g[u])if(v!=fat)dfs(v,u);
      |                  ^
answer.code: In function ‘void solve()’:
answer.code:39:30: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   39 |     for(i=2;i<=n;i++)pq.push({i,a[i],b[i]});
      |                              ^
answer.code:39:29: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   39 |     for(i=2;i<=n;i++)pq.push({i,a[i],b[i]});
      |                      ~~~~~~~^~~~~~~~~~~~~~~
answer.code:45:38: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   45 |         p[u]=v,a[v]=c,b[v]=d,pq.push({v,a[v],b[v]});
      |                                      ^
answer.code:45:37: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   45 |         p[u]=v,a[v]=c,b[v]=d,pq.push({v,a[v],b[v]});
      |                              ~~~~~~~^~~~~~~~~~~~~~~