QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790195#7588. Monster HunterKFCCompile Error//C++982.6kb2024-11-28 07:51:012024-11-28 07:51:06

Judging History

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

  • [2024-11-28 07:51:06]
  • 评测
  • [2024-11-28 07:51:01]
  • 提交

answer

// Hydro submission #6747b0639592d6097b871737@1732751459750
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>

#define N 100009
#define LL long long
#define pii pair<int,int>
using namespace std;
int n,idx=1,h[N],eg[N*2],ne[N*2],fa[N],die[N];
int tim[N];
LL a[N],b[N];
struct node1{
    LL a,b;
    int t,id;
    bool operator<(const node1 c)const{
        return a>c.a;
    }
};
struct node2{
    LL a,b;
    int t,id;
    bool operator<(const node2 c)const{
        return b<c.b;
    }
};
priority_queue<node1> q1;
priority_queue<node2> q2;
void add(int a,int b){
    ++idx,eg[idx]=b,ne[idx]=h[a],h[a]=idx;
}
void dfs(int u){
    for(int y,i=h[u];i;i=ne[i]){
        y=eg[i];
        if(y==die[u]) continue;
        die[y]=u;
        dfs(y);
    }
}
int find(int u){
    if(fa[u]==u) return u;
    return fa[u]=find(fa[u]);
}
void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) fa[i]=i,tim[i]=h[i]=0;
    a[1]=b[1]=0;
    idx=1;
    for(int i=2;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]);
    for(int a,b,i=1;i<n;i++){
        scanf("%d%d",&a,&b);
        add(a,b);
        add(b,a);
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        if(a[i]<=b[i]) q1.push({a[i],b[i],0,i});
        else q2.push({a[i],b[i],0,i});
    }
    int tot=0;
    while(q1.size() || q2.size()){
        if(q1.size()){
            node1 u=q1.top();
            q1.pop();
            if(u.t<tim[u.id]) continue;
            int y=find(u.id);
            if(y>1){
                int t=find(die[y]);
                fa[y]=t;
                LL mb=-a[t]+b[t]-a[y]+b[y];
                a[t]=-min(-a[t],-a[t]+b[t]-a[y]);
                b[t]=mb+a[t];
                tim[t]=++tot;
                if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
                else q2.push({a[t],b[t],tot,t});
            }
        }else{
            node2 u=q2.top();
            q2.pop();
            if(u.t<tim[u.id]) continue;
            int y=find(u.id);
            if(y>1){
                int t=find(die[y]);
                fa[y]=t;
                LL mb=-a[t]+b[t]-a[y]+b[y];
                a[t]=-min(-a[t],-a[t]+b[t]-a[y]);
                b[t]=mb+a[t];
                tim[t]=++tot;
                if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
                else q2.push({a[t],b[t],tot,t});
            }
        }
    }
    printf("%lld",a[1]);
}
int main() {
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++) solve();
    // freopen("tree.in","r",stdin);
    // freopen("tree.out","w",stdout);
    
    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:47:5: error: ‘scanf’ was not declared in this scope; did you mean ‘wscanf’?
   47 |     scanf("%d",&n);
      |     ^~~~~
      |     wscanf
answer.code:59:32: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   59 |         if(a[i]<=b[i]) q1.push({a[i],b[i],0,i});
      |                                ^
answer.code:59:31: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   59 |         if(a[i]<=b[i]) q1.push({a[i],b[i],0,i});
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~
answer.code:60:22: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   60 |         else q2.push({a[i],b[i],0,i});
      |                      ^
answer.code:60:21: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   60 |         else q2.push({a[i],b[i],0,i});
      |              ~~~~~~~^~~~~~~~~~~~~~~~~
answer.code:76:40: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   76 |                 if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
      |                                        ^
answer.code:76:39: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   76 |                 if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~
answer.code:77:30: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   77 |                 else q2.push({a[t],b[t],tot,t});
      |                              ^
answer.code:77:29: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   77 |                 else q2.push({a[t],b[t],tot,t});
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~
answer.code:91:40: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   91 |                 if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
      |                                        ^
answer.code:91:39: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   91 |                 if(a[t]<=b[t]) q1.push({a[t],b[t],tot,t});
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~
answer.code:92:30: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   92 |                 else q2.push({a[t],b[t],tot,t});
      |                              ^
answer.code:92:29: warning: extended initializer lists only available with ‘-std=c++11’ or ‘-std=gnu++11’ [-Wc++11-extensions]
   92 |                 else q2.push({a[t],b[t],tot,t});
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~
answer.code:96:5: error: ‘printf’ was not declared in this scope
   96 |     printf("%lld",a[1]);
      |     ^~~~~~
answer.code:7:1: note: ‘printf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’?
    6 | #include<queue>
  +++ |+#include <cstdio>
    7 | 
answer.code: In function ‘int main()’:
answer.code:100:5: error: ‘scanf’ was not declared in this scope; did you mean ‘wscanf’?
  100 |     scanf("%d",&t);
      |     ^~~~~
      |     wscanf