QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#788240 | #7588. Monster Hunter | KFC | WA | 1ms | 6852kb | C++17 | 1.4kb | 2024-11-27 16:19:43 | 2024-11-27 16:19:47 |
Judging History
answer
// Hydro submission #6746d61d9592d6097b8682d3@1732695582438
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+5;
int n;
ll a[N],b[N];
ll be[N];
vector<int> e[N];
int fa[N];
void dfs(int no,int ff){
fa[no]=ff;
for(int to:e[no]){
if(to==ff)continue;
dfs(to,no);
}
}
struct node{
int id;
ll a,b;
bool fl;
node()=default;
node(int id,ll a,ll b):id(id),a(a),b(b),fl(a<=b){}
bool operator<(const node& y)const{
if(fl!=y.fl)return fl<y.fl;
if(fl)return a>y.a;
return b<y.b;
}
};
priority_queue<node> q;
int f[N];
bool fl[N];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int main(){
scanf("%d",&n);
for(int i=2;i<=n;++i)scanf("%lld%lld",&a[i],&b[i]);
for(int i=1;i<n;++i){
int u,v;
scanf("%d%d",&u,&v);
e[u].push_back(v);
e[v].push_back(u);
}
for(int i=1;i<=n;++i)f[i]=i;
dfs(1,0);
for(int i=2;i<=n;++i){
be[i]=a[i];
q.emplace(i,a[i],b[i]);
}
while(!q.empty()){
int no=q.top().id;
q.pop();
if(fl[no])continue;
fl[no]=1;
int fid=find(fa[no]);
be[fid]=max(be[fid],be[no]-(b[fid]-a[fid]));
b[fid]+=b[no];
a[fid]+=a[no];
f[no]=fid;
if(fid!=1)q.emplace(fid,a[fid],b[fid]);
}
printf("%lld\n",be[1]);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6852kb
input:
1 4 2 6 5 4 6 2 1 2 2 3 3 4
output:
0
result:
wrong answer 1st numbers differ - expected: '3', found: '0'