QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787993 | #7588. Monster Hunter | konata2828 | WA | 1ms | 8168kb | C++17 | 1.4kb | 2024-11-27 15:30:37 | 2024-11-27 15:30:38 |
Judging History
answer
// Hydro submission #6746ca9b9592d6097b86679c@1732692636465
#include<bits/stdc++.h>
using namespace std;
namespace ax_by_c{
typedef long long ll;
const int N=1e5+5;
int n;
ll a[N],b[N];
vector<int>g[N];
int fa[N];
void dfs(int u){
for(auto v:g[u]){
if(v==fa[u])continue;
fa[v]=u;
dfs(v);
}
}
struct node{
int u;
ll a,b;
bool operator < (const node& y)const{
if(b-a>=0&&y.b-y.a<0)return 0;
if(b-a<0&&y.b-y.a>=0)return 1;
if(b-a>=0)return a>y.a;
else return b<y.b;
}
};
bool vis[N];
int find(int u){
if(!vis[u])return u;
return fa[u]=find(fa[u]);
}
void main(){
scanf("%d",&n);
for(int i=2;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]);
for(int i=1,x,y;i<n;i++){
scanf("%d %d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1);
priority_queue<node>pq;
for(int i=2;i<=n;i++)pq.push({i,a[i],b[i]});
ll ans=0,cur=0;
while(pq.size()){
auto tmp=pq.top();
pq.pop();
if(vis[tmp.u]||a[tmp.u]!=tmp.a||b[tmp.u]!=tmp.b)continue;
vis[tmp.u]=1;
int pos=find(tmp.u);
if(pos==1){
if(cur<tmp.a){
ans+=tmp.a-cur;
cur=tmp.a;
}
cur-=tmp.a;
cur+=tmp.b;
}
else{
ll ttmp=max(a[pos],a[pos]-b[pos]+tmp.a);
b[pos]=b[pos]-a[pos]+tmp.b-tmp.a+ttmp;
a[pos]=ttmp;
pq.push({pos,a[pos],b[pos]});
}
}
printf("%lld\n",ans);
}
}
int main(){
ax_by_c::main();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 8168kb
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'