1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| const int INF=0x3f3f3f3f; const int MAX=200+10; int n,t,d[MAX]; struct Edge{ int next,to,c; }edge[MAX*MAX]; int tot,head[MAX]; void init(){ tot=0; mem(head,-1); } void addedge(int u,int v,int c){ edge[tot].to=v; edge[tot].c=c; edge[tot].next=head[u]; head[u]=tot++; } bool spfa(int s){ queue<int>q; bool inq[MAX]; for(int i=1;i<=n;i++) d[i] = INF; mem(inq,0); d[s]=0; q.push(s); while(!q.empty()){ int u= q.front(); q.pop(); inq[u]=0; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].to; int c=edge[i].c; if(d[v] > d[u] +c){ d[v] = d[u] +c; if(!inq[v]){ inq[v]=1; q.push(v); } } } } return true; } int main(){ freopen("in","r",stdin); sf(n); init(); fi(i,1,n) fi(j,i+1,n+1){ sf(t); addedge(i,j,t); } spfa(1); pf(d[n]); return 0; }
|