- Time: 2016-04-08-18:05:09
- Title number: [2016-04-08][poj][3159][candies]
- The main topic: N Children, m information, each message A, B, C, said B children get sugar can not be more than a child C, ask N children than 1 children can more than the maximum number of
- Analysis: Direct is to ask for 1 to n the shortest path (if not the minimum, then the other side, there is always a situation can not meet the most short-circuit this side of the situation,), run directly once Dijkstra
- Problem encountered: Using ' vector ' to save the graph tle, changed to an array implementation of the adjacency table is a
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 3 * 1E4 + 10;
const int maxe = 15 * 1e4 + 10
int mhead[maxn],nxt[maxe],mend[maxe],mcost[maxe],q;
int vis[maxn],d[maxn];
inline void addedge(int from,int to,int c){
mend[q] = to;
nxt[q] = mhead[from];
mcost[q] = c;
mhead[from] = q++;
}
inline void ini(){
memset(mhead,-1,sizeof(mhead));
q = 2;
}
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;
}
};
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 e = mhead[u];~e;e = nxt[e]){
int v = mend [ e ;
if (! vis [ v ] && D [ v ] > D [ u + mcost [ e
d[v] = d[u] + mcost[e];
q.push(mNode(v,d[v]));
}
}
}
}
int main(){
int n,m,a,b,c;
ini();
scanf("%d%d",&n,&m);
for(int i = 0 ; i < m ; ++i){
scanf("%d%d%d",&a,&b,&c);
addedge(a,b,c);
}
Dijkstra(1);
printf("%d\n",d[n]);
return 0;
}
From for notes (Wiz)
[2016-04-08] [POJ] [3159] [Candies]