tjut 2851
来源:互联网 发布:帧中继网络 编辑:程序博客网 时间:2024/05/01 19:47
#include <cstdio>#include <cstring>#include <vector>#include <queue>using namespace std;const int maxn = 2010;const int INF = 1<<30;int n,m;struct node{ int x,y,cost;}f[maxn];struct edge{ int to,cost; edge(){} edge(int x,int y) { to=x; cost=y; }};typedef pair<int,int>P;vector<edge>G[maxn];int d[maxn];void dijkstra(int s){ priority_queue<P,vector<P>,greater<P> >que; for(int i=1;i<=maxn;i++) d[i]=INF; d[s]=f[1].cost; que.push(P(f[1].cost,s)); while(!que.empty()) { P p=que.top();que.pop(); int v=p.second; if(d[v]<p.first) continue; for(int i=0;i<G[v].size();i++) { edge e=G[v][i]; if(d[e.to]>d[v]+e.cost) { d[e.to]=d[v]+e.cost; que.push(P(d[e.to],e.to)); } } }}int main(){ //freopen("a.txt","r",stdin); int t,k; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { G[i].clear(); scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].cost); } //printf("%d\n",n); for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) if(f[j].x<=f[i].y) { G[i].push_back(edge(j,f[j].cost)); // printf("%d %d %d\n",i,j,p[i].cost+p[j].cost); } } dijkstra(1); for(int i=0;i<m;i++) { scanf("%d",&k); if(d[k]==INF) printf("-1\n"); else printf("%d\n",d[k]); } } return 0;}
0 0
- tjut 2851
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- javascript_lesson4_函数
- jQuery使用ajaxSubmit()提交表单示例
- CoordinatorLayout用法学习
- 用Linux命令查看Linux的最大可用内存
- clone failed. Could not read from remote repository".
- tjut 2851
- oracle中与mysql中的命令 show databases, show tables, desc table类似的命令集
- 笔刷载入路径&光照实现立体化——电缆
- 【zzulioj 1913 小火山的计算能力】
- HDU1028——Ignatius and the Princess III(背包问题dp)
- 无法远程访问Mysql
- HBuilder使用夜神模拟器调试Android应用
- android 模拟输入设备
- 题目堆