每次利用释放的点更新floyd,相当于最多跑了一个完整的floyd
没超时是真星
https://v4t.jk1507.cn/contest.php?cid=46
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int a[305][305];
bool vis[305];
//int pos[305];
int n, m, q;
void init()
{
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++)
if(i == j) a[i][j] = 0;
else a[i][j] = inf;
}
int main()
{
int cas = 0;
while(scanf("%d%d%d",&n,&m,&q) != EOF && (n + m + q))
{
int u, v, w;
init();
for(int i = 1; i <= m; i ++)
{
scanf("%d%d%d",&u,&v,&w);
if(a[u][v] > w) a[u][v] = w;
}
//int cnt = 0;
map<int, int> ma;
printf("Case %d:\n", ++ cas);
while(q --)
{
int k;
scanf("%d", &k);
if(k == 0)
{
int tmp;
scanf("%d", &tmp);
if(ma[tmp])
printf("City %d is already recaptured.\n", tmp);
else {
ma[tmp] = 1;
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++)
a[i][j] = min(a[i][tmp] + a[tmp][j], a[i][j]);
//pos[++ cnt] = tmp;
}
}
else
{
int u, v;
scanf("%d%d", &u, &v);
memset(vis, 0, sizeof(vis));
if(! ma[u] || ! ma[v]) printf("City %d or %d is not available.\n", u, v);
else
{
if(a[u][v] == inf) printf("No such path.\n");
else printf("%d\n", a[u][v]);
}
}
}
printf("\n");
}
return 0;
}