标签:name color mit bsp ica clu query iss element
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1100 Accepted Submission(s): 219
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 1e5 + 10; struct node{ ll to,val; bool operator<(const node& s)const { return val>s.val; } }; int T,n,m,q,query[maxn]; ll ans[maxn]; vector<pii>e[maxn]; priority_queue<node>Q; multiset<int>s; int main() { //freopen("1.txt", "r", stdin); scanf("%d", &T); while (T--) { scanf("%d%d%d",&n,&m,&q); s.clear(); while(!Q.empty())Q.pop(); for(register int i=1;i<=n;++i)e[i].clear(); for(register int i=1,u,v,w;i<=m;++i){ scanf("%d%d%d",&u,&v,&w); e[u].emplace_back(make_pair(w,v)); s.insert(w); Q.push(node{v,w}); } for(register int i=1;i<=n;++i){ sort(e[i].begin(),e[i].end()); } int mx=-1; for(register int i=1,k;i<=q;++i){ scanf("%d",&query[i]); mx=max(mx,query[i]); } int cnt=0; while(cnt<mx){ node cur=Q.top(); Q.pop(); ans[++cnt]=cur.val; if(cnt>=mx)break; int u=cur.to; for(auto it:e[u]){ ll v=it.second; ll d=cur.val+it.first; if(s.size()==mx){ auto po=--s.end(); if(d>=*po)break; s.erase(po); s.insert(d); } else{ s.insert(d); } Q.push(node{v,d}); } } for(register int i=1;i<=q;++i){ printf("%d\n",ans[query[i]]); } } return 0; }
标签:name color mit bsp ica clu query iss element
原文地址:https://www.cnblogs.com/czy-power/p/11404431.html