

#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=1e6+5; 
int idx;//第idx条边
int e[N];//终点 
int h[N];//h[a]=idx表示节点a后第一条边后是第idx条 
int ne[N];//ne[idx]=x第idx条边后面是第x条边 
int w[N]; //第idx条边的权值 
void add(int x,int y,int z)//x->y 权值为c 
{
		e[idx]=y;//第idx条边终点为y  即->y 
		ne[idx]=h[x];//第idx条由于是a后边,要连到a后的第一条边,将原来a后的头边放在第idx条边后面 
		w[idx]=z;//第idx条边的权值 
		h[x]=idx++;//a后第一条边为是idx后一条 
}
int main()
{
	memset(h,-1,sizeof(h));
	cin>>n>>m;
	while(m--)
	{
		int x,y,z;
		cin>>x>>y>>z;
		add(x,y,z);
	}
	for(int i=1;i<=n;i++)
	{
		cout<<i<<":";
		for(int j=h[i];j!=-1;j=ne[j])
		{
			printf("(%d,%d)->",e[j],w[j]);
		}
		cout<<endl;
	}
}
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=1e5+5;
int idx;
int e[N];//终点 
int h[N];//后一条边 
int ne[N];//下一条边 
int w[N];//权值 
int d[N];//表示起点到i的最短路径
bool v[N];//标记 	
void add(int a,int b,int c)//a->b 权值c
{
	e[idx]=b;//第idx条边终点为y  即->y 
	ne[idx]=h[a];//第idx条由于是a后边,要连到a后的第一条边,将原来a后的头边放在第idx条边后面 
	w[idx]=c;//第idx条边的权值 
	h[a]=idx++;//a后第一条边为是idx后一条 
 } 
int main()
{
	memset(h,-1,sizeof(h));
	memset(d,0x3f,sizeof(d));
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v,c;
		cin>>u>>v>>c;
		add(u,v,c);
	}
	d[1]=0;
	for(int i=1;i<=n;i++)//把n个点都标记 
	{
		int dot=-1;//本轮要标记的点
		for(int j=1;j<=n;j++)
		{
			 if(v[j]==0&&(dot==-1||d[dot]>d[j])) 
			 {
			 	dot=j;
			 }
		 } 
		 v[dot]=1;
		 for(int j=h[dot];j!=-1;j=ne[j])
		 {
		 	int dot2=e[j];//第j条边的终点
			d[dot2]	=min(d[dot2],d[dot]+w[j ])
		 }
	}
	cout<<d[n];
}
朱老师团队