QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386806 | #8235. Top Cluster | sunkuangzheng | WA | 3ms | 11832kb | C++23 | 1.9kb | 2024-04-11 20:20:36 | 2024-04-11 20:20:36 |
Judging History
answer
/**
* author: sunkuangzheng
* created: 11.04.2024 20:01:39
**/
#include<bits/stdc++.h>
#ifdef DEBUG_LOCAL
#include <mydebug/debug.h>
#endif
using ll = long long;
const int N = 5e5+5;
using namespace std;
int T,n,m,a[N],ok[N],u,v,w,siz[N],tt,rt,vis[N],t[N],ans[N],re = 1e9; vector<pair<int,int>> g[N]; vector<int> b;
vector<pair<int,ll>> tp,qu,uq[N]; ll k; vector<ll> ds;
#define ff for(auto [v,w] : g[u]) if(!vis[v] && v != f)
void upd(int x,int k){for(;x;x -= x & -x) t[x] = min(t[x],k);}
int qry(int x){for(re = 1e9;x <= n;x += x & -x) re = min(re,t[x]); return re;}
void clr(int x){for(;x;x -= x & -x) t[x] = 1e9;}
void dfs1(int u,int f,int sz){
siz[u] = 1; int mx = 0;
ff dfs1(v,u,sz),siz[u] += siz[v],mx = max(mx,siz[v]);
if(mx = max(mx,sz - siz[u]),mx < tt) tt = mx,rt = u;
}void dfs2(int u,int f,ll d){
tp.emplace_back(a[u],d),ds.push_back(d);
for(auto i : uq[u]) qu.emplace_back(i);
ff dfs2(v,u,d+w);
}void solve(int u){
tp.clear(),ds.clear(),dfs2(u,0,0);
sort(ds.begin(),ds.end()),ds.erase(unique(ds.begin(),ds.end()));
for(auto &[x,k] : tp) k = lower_bound(ds.begin(),ds.end(),k) - ds.begin() + 1,upd(k,x);
for(auto &[x,k] : qu) k = lower_bound(ds.begin(),ds.end(),k+1) - ds.begin() + 1,ans[x] = min(ans[x],qry(k));
for(auto [x,k] : tp) clr(k);
}void dfs2(int u,int f){solve(u),vis[u] = 1; ff tt = 1e9,dfs1(v,0,siz[v]),dfs2(rt,0);}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i ++)
if(cin >> a[i],b.push_back(a[i]),a[i] <= n) ok[a[i]] = 1;
int mex = 0; while(ok[mex]) mex ++;
fill(ans+1,ans+m+1,mex),fill(t+1,t+n+1,1e9);
for(int i = 1;i < n;i ++) cin >> u >> v >> w,g[u].emplace_back(v,w),g[v].emplace_back(u,w);
for(int i = 1;i <= m;i ++) cin >> u >> k,uq[u].emplace_back(i,k);
tt = 1e9,dfs1(1,0,n),dfs2(rt,0);
for(int i = 1;i <= m;i ++) cout << ans[i] << "\n";
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 11832kb
input:
5 4 3 9 0 1 2 1 2 10 3 1 4 3 4 3 3 5 2 3 0 1 0 4 6 4 7
output:
1 1 1 1
result:
wrong answer 2nd numbers differ - expected: '0', found: '1'