​经典算法无需注解​

测试数据:
4 5
1 2 1
2 4 4
1 4 8
1 3 2
3 4 1
1 4

#include<bits/stdc++.h>
#define MAXN 111
using namespace std;
vector<pair<int,int>> E[MAXN];
//m个节点 n条边 从1开始
int m,n;
int d[MAXN];
void init()
{
for(int i = 0;i <= m;i++)
{
E[i].clear();
d[i]=1e9;
}
}
int main()
{
freopen("in.txt","r",stdin);
cin >> m >> n;
init();
for(int i = 0;i < n;i++)
{
//z表示距离
int x,y,z;
cin >> x >> y >>z;
E[x].push_back(make_pair(y,z));
}
//起始点到终点
int s,e;
cin >> s >> e;
priority_queue<pair<int,int>> Q;
d[s] = 0;
Q.push(make_pair(-d[s],s));
while(!Q.empty()){
int now = Q.top().second;
Q.pop();
if(now == e)
break;

int size = E[now].size();
for(int i = 0;i < size;i++)
{
int v = E[now][i].first;
if(d[v]>d[now]+E[now][i].second)
{
d[v] = d[now]+E[now][i].second;
Q.push(make_pair(-d[v],v));
}
}
}
cout << d[e] << endl;
}