2019ccpc缃戠粶璧沨du6705 path
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019ccpc缃戠粶璧沨du6705 path相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/typedef' title='typedef'>typedef clu back top push ref pac priority lin
path
瑙i鎬濊矾
鍏堢敤vector瀛樺浘锛岀劧鍚庡皢姣忎釜vector鎸夌収杈圭殑鏉冨€间粠灏忓埌澶ф帓搴忋€傚皢姣忎釜椤剁偣浣滀负璧风偣鐨勮竟閲屾渶鐭殑杈瑰瓨鍏ヤ紭鍏堥槦鍒椼€傚浜庡瓨鍏ョ殑璺緞鐨勪俊鎭紝搴旀湁璧风偣锛岀粓鐐癸紝鏉冨€硷紝浠ュ強鏈€鏂板姞鍏ョ殑杈规槸鍏惰捣鐐圭殑绗嚑鐭竟銆備紭鍏堥槦鍒楁寜鐓ф潈鍊间粠灏忓埌澶ф帓搴忥紝姣忔鍑洪槦褰撳墠鏈€鐭殑璺緞锛屽浜庝竴鏉¤矾寰勶紝鏇存柊涓ゆ潯鏂扮殑鍙兘鏈€鐭殑璺緞锛屽嵆杩欐潯璺悗闈㈠姞涓婁竴鏉″彲璧扮殑鏈€鐭竟锛屼互鍙婅繖鏉¤矾鏈€鍚庝竴鏉¤竟鎹㈡垚涓€鏉℃鐭竟銆傚皢璇㈤棶鎺掑簭锛屼笉鏂洿鏂扮瓟妗堝嵆鍙€?/p>
浠g爜濡備笅
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 100010;
struct T
int x, y, f;
ll w;
T(int x, int y, ll w, int f): x(x), y(y), w(w), f(f)
bool operator<(const T& a)const
return w > a.w;
;
struct line
int r;
ll w;
line(int r, ll w): r(r), w(w)
bool operator<(const line& a)const
return w < a.w;
;
vector<line> vec[N];
struct R
int i, k;
bool operator<(const R& a)const
return k < a.k;
qy[N];
ll ans[N];
priority_queue<T> pq;
int main()
int t;
scanf("%d", &t);
while(t --)
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= m; i ++)
int u, v;
ll w;
scanf("%d%d%lld", &u, &v, &w);
vec[u].push_back(line(v, w));
for(int i = 1; i <= n; i ++)
sort(vec[i].begin(), vec[i].end());
for(int i = 1; i <= n; i ++)
if(vec[i].size())
pq.push(T(i, vec[i][0].r, vec[i][0].w, 0));
for(int i = 1; i <= q; i ++)
scanf("%d", &qy[i].k);
qy[i].i = i;
sort(qy + 1, qy + q + 1);
int cnt = 0;
int id = 1;
while(!pq.empty())
int x = pq.top().x;
int y = pq.top().y;
ll w = pq.top().w;
int f = pq.top().f;
pq.pop();
++cnt;
while(id <= q && cnt == qy[id].k)
ans[qy[id].i] = w;
++id;
if(id > q)
break;
if(vec[y].size())
pq.push(T(y, vec[y][0].r, w + vec[y][0].w, 0));
if(vec[x].size() > f + 1)
pq.push(T(x, vec[x][f + 1].r, w + vec[x][f + 1].w - vec[x][f].w, f + 1));
for(int i = 1; i <= q; i ++)
printf("%lld\n", ans[i]);
for(int i = 0; i <= n; i ++)
vec[i].clear();
while(!pq.empty())
pq.pop();
return 0;
以上是关于2019ccpc缃戠粶璧沨du6705 path的主要内容,如果未能解决你的问题,请参考以下文章