洛谷:P1476 休息中的小呆
如何评价这种 题意描述 比较贴切?
翻译:求最短路,同时升序输出最短路上的点(包含不同路径的最短路)
数据范围一眼 Floyd
但这个输出路径的 Floyd 应用蛮鱿鱼丝的
代码:
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#define mem(a,b) memset(a,b,sizeof a)
#define cinios (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))
#define sca scanf
#define pri printf
#define ul (u << 1)
#define ur (u << 1 | 1)
#define fx first
#define fy second
//#pragma GCC optimize(2)
//[博客地址](https://blog.csdn.net/weixin_51797626?t=1)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 110, M = 210, MM = 3000010;
int INF = 0x3f3f3f3f, mod = 100003;
ll LNF = 0x3f3f3f3f3f3f3f3f;
int n, m, k, T, S, D;
int g[N][N];
void floyd() {
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
g[i][j] = max(g[i][j], g[i][k] + g[k][j]);//求最短路
cout << g[1][n] << endl;
for (int i = 1; i <= n; i++)//枚举时就是升序
if (g[1][i] + g[i][n] == g[1][n])//判断中间点来输出
cout << i << ' ';
//巧妙
}
int main() {
cin >> n >> m;
n++;//还少了个点,呵呵,题意just like shit
mem(g, -0x3f);
for (int i = 1; i <= n; i++)g[i][i] = 0;
while (m--)
{
int a, b, x;
cin >> a >> b >> x;
g[a][b] = x;
}
floyd();
return 0;
}