- Time: 2016-04-02-10:34:36 Saturday
- Title Number: [2016-04-02][poj][2387][til the Cows Come Home]
- Topic: given n nodes and T-path, the shortest-circuit length of N to 1 is obtained.
- Analysis: Run the shortest possible time
- Problems encountered:
- is said to be multiple sides, if the adjacency matrix is used to update the minimum value,
- This problem is first input t, and then enter N, input the time to read wrong, infinite wa ...
#include <queue>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1000 + 10;
const int maxe = 2000 + 10;
struct mNode{
int u,c;
Mnode ( int _u = 0 int _c = 0 ): u ( _u c ( _c
bool operator < (const mNode & a)const{
return c > a.c;
}
};
struct Edge{
int v,c;
Edge(int _v = 0,int _c = 0):v(_v),c(_c){}
};
vector<Edge> e[maxe];
bool vis[maxn];
int d[maxn];
void Dijkstra(int s){
memset(vis,0,sizeof(vis));
memset(d,0x3f,sizeof(d));
priority_queue<mNode> q;
d[s] = 0;
q.push(mNode(s,0));
mNode tmp;
while(!q.empty()){
tmp = q.top();
q.pop();
int u = tmp.u;
if(vis[u]) continue;
vis[u] = 1;
for(int i = 0;i < e[u].size();++i){
Edge & me = e[u][i];
if (! vis [ me v && D [ me v > D Span class= "pun" >[ u ] + me c
D [me v = D [ u ] + me c
q.push(mNode(me.v,d[me.v]));
}
}
}
}
inline void addedge(int u,int v,int c){
e[u].push_back(Edge(v,c));
}
int main(){
int n,t,a,b,c;
scanf("%d%d",&t,&n);
for(int i = 0;i < t; ++i){
scanf("%d%d%d",&a,&b,&c);
addedge(a,b,c);
addedge(b,a,c);
}
Dijkstra(n);
printf("%d\n",d[1]);
return 0;
}
From for notes (Wiz)
[2016-04-02] [POJ] [2387] [Til the Cows Come Home]