标签:最大 cli bool lines any panel integer 第k大 tar
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 5e4+5; 5 int n,m,k,t,q; 6 typedef pair<int,int>p; 7 typedef long long ll; 8 vector<p>node[maxn]; 9 10 ll ans[maxn]; 11 int Q[maxn]; 12 13 struct Point 14 { 15 ll val; 16 int now,id; 17 Point(ll val,int now,int id):val(val),now(now),id(id){} 18 bool operator<(const Point &b)const{ 19 return val > b.val; 20 } 21 }; 22 23 priority_queue<Point>que; 24 void bfs(int limit) 25 { 26 while(!que.empty())que.pop(); 27 for(int i=1;i<=n;i++)sort(node[i].begin(),node[i].end()); 28 for(int i=1;i<=n;i++) 29 { 30 if(!node[i].empty())que.push(Point(node[i][0].first,i,0)); 31 } 32 int tot = 0; 33 while(!que.empty()) 34 { 35 Point tmp = que.top(); 36 que.pop(); 37 ll cost = tmp.val; 38 int now = tmp.now; 39 int id = tmp.id; 40 if(++tot > limit)return; 41 ans[tot] = cost; 42 if(id < node[now].size() - 1) 43 { 44 que.push(Point(cost-node[now][id].first+node[now][id+1].first,now,id+1)); 45 } 46 if(!node[node[now][id].second].empty()) 47 { 48 que.push(Point(cost+node[node[now][id].second][0].first,node[now][id].second,0)); 49 } 50 } 51 } 52 53 int main() 54 { 55 scanf("%d",&t); 56 while(t--) 57 { 58 scanf("%d%d%d",&n,&m,&q); 59 int maxx = 0; 60 for(int i=1;i<=n;i++)node[i].clear(); 61 for(int i=1;i<=m;i++) 62 { 63 int u,v,w; 64 scanf("%d%d%d",&u,&v,&w); 65 node[u].push_back(p(w,v)); 66 } 67 for(int i=1;i<=q;i++) 68 { 69 scanf("%d",&Q[i]); 70 maxx = max(maxx,Q[i]); 71 } 72 bfs(maxx); 73 for(int i=1;i<=q;i++) 74 { 75 printf("%lld\n",ans[Q[i]]); 76 } 77 } 78 }
标签:最大 cli bool lines any panel integer 第k大 tar
原文地址:https://www.cnblogs.com/iwannabe/p/11402800.html