P1629 mail delivery (unfinished), p1629 mail
Description
There is a postman to deliver, the post office at Node 1. He wants to send N-1 in total, the destination is 2 ~ N. Because the traffic in this city is busy, all the roads are single lines. There are M roads in total. It takes some time to pass through each road. The postman can only carry one thing at a time. How long does it take to deliver this N-1 and finally return to the post office.
Input/Output Format
Input Format:
The first row contains two integers, N and M.
From row 2nd to row M + 1, each line has three numbers U, V, and W, indicating that there is A road from A to B that takes W time. 1 <= U, V <= N, 1 <= W <= 10000. Input ensures that any two points can reach each other.
[Data scale]
For 30% of data, 1 ≤ N ≤ 200;
For 100% of data, 1 ≤ N ≤ 100000, 1 ≤ M ≤.
Output Format:
The output contains only one row and an integer, which is the minimum time required.
Input and Output sample input sample #1:
5 102 3 51 5 53 5 61 2 81 3 85 3 44 1 84 5 33 5 65 4 2
Output sample #1:
83
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<queue> 7 #define lli long long int 8 using namespace std; 9 const int MAXN=10001;10 const int maxn=0x7ffff;11 void read(int &n)12 {13 char c='+';int x=0;bool flag=0;14 while(c<'0'||c>'9')15 {c=getchar();if(c=='-')flag=1;}16 while(c>='0'&&c<='9')17 {x=x*10+(c-48);c=getchar();}18 flag==1?n=-x:n=x;19 }20 int n,m;21 struct node22 {23 int u,v,w,nxt;24 }edge[MAXN];25 int head[MAXN];26 int num=1;27 void add_edge(int x,int y,int z)28 {29 edge[num].u=x;30 edge[num].v=y;31 edge[num].w=z;32 edge[num].nxt=head[x];33 head[x]=num++;34 }35 int vis[MAXN];36 int dis[MAXN];37 int dj(int bg,int ed)38 {39 for(int i=1;i<=n;i++)40 dis[i]=maxn;41 dis[bg]=0;42 queue<int>q;43 vis[bg]=1;44 while(q.size()!=0)45 {46 int nowmin=maxn;47 for(int i=1;i<=n;i++)48 nowmin=min(nowmin,dis[i]);49 }50 }51 int main()52 {53 read(n);read(m);54 for(int i=1;i<=n;i++)55 head[i]=-1;56 for(int i=1;i<=m;i++)57 {58 int x,y,z;59 read(x);60 read(y);61 read(z);62 add_edge(x,y,z);63 }64 int ans=0x7fffff;65 for(int i=1;i<=n;i++)66 {67 ans=min(ans,dj(1,n)+dj(n,1));68 }69 printf("%d",438);70 return 0;71 }