https://www.luogu.org/problemnew/show/P1608
#include <bits/stdc++.h>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define ll long long
#define ld long double
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b)/(__gcd((a),(b))))
#define mod 100003
#define MP make_pair
#define PI pair<int,int>
using namespace std;
const int N = 4e6 + 10;
int n, e, h[N], cnt, dis[N], inq[N], path[N], ap[N], mp[2010][2010]; //有多少个小镇及有多少边的信息。
struct node {
int v, w, net;
} no[N];
void add(int u, int v, int w) {
no[cnt].v = v;
no[cnt].w = w;
no[cnt].net = h[u];
h[u] = cnt++;
}
void spfa(int s) {
queue<int> q;
dis[s] = 0, inq[s] = 1, ap[s] = path[s] = 1;
q.push(s);
while(!q.empty()) {
int u = q.front();
q.pop();
inq[u] = 0;
for(int i = h[u]; i != -1; i = no[i].net) {
int v = no[i].v, w = no[i].w;
if(dis[v] == dis[u] + w) {
path[v] += ap[u];
ap[v] += ap[u];
if(!inq[v] && path[v]) {
inq[v] = 1;
q.push(v);
}
} else if(dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
path[v] = ap[v] = ap[u];
if(!inq[v] && path[v]) {
inq[v] = 1;
q.push(v);
}
}
}
ap[u] = 0;
}
}
int main() {
cin >> n >> e;
mem(h, -1), mem(dis, 0x3f);
for(int a, b, c, i = 0; i < e; i++) {
cin >> a >> b >> c;
if(mp[a][b] > c || mp[a][b] == 0) {
add(a, b, c);
mp[a][b] = c;
}
}
spfa(1);
if(dis[n] != INF)
cout << dis[n] << " " << path[n] << endl;
else
cout << "No answer";
return 0;
}