poj 2387 Til the Cows Come Home
2017-05-04 20:49
489 查看
题目链接:Til the Cows Come Home
题目大意:给你m条边,n个点,然后给你这m条边的两个点和边权,求从n点到1点的最短路,保证有解
题目思路:最短路裸题,直接dij即可
题目大意:给你m条边,n个点,然后给你这m条边的两个点和边权,求从n点到1点的最短路,保证有解
题目思路:最短路裸题,直接dij即可
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include <vector> #include <queue> using namespace std; const int maxn = 2005; vector<pair<int ,int > >E[maxn]; int d[maxn]; int n,m,s,t,x,y,z; void init(){ for(int i = 0;i < maxn;i++){ E[i].clear(); d[i] = 1e9; } } int main(){ while(~scanf("%d%d",&m,&n)){ init(); while(m--){ scanf("%d%d%d",&x,&y,&z); E[x].push_back(make_pair(y,z)); E[y].push_back(make_pair(x,z)); } priority_queue<pair<int,int> >Q; Q.push(make_pair(-d ,n)); d = 0; while(!Q.empty()){ int now = Q.top().second; Q.pop(); for(int i = 0;i < E[now].size();i++){ int v = E[now][i].first; if(d[v]>d[now]+E[now][i].second){ d[v] = d[now]+E[now][i].second; Q.push(make_pair(-d[v],v)); } } } printf("%d\n",d[1]); } return 0; }
相关文章推荐
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj_2387_Til the Cows Come Home
- 迪杰斯特拉 示例 : poj 2387 Til the Cows Come Home
- poj-2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- 迪杰斯特拉 示例 : poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ -- 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- Poj 2387 Til the Cows Come Home