每当标记一个点,就一个点为松弛的点,做一次floyd。最多一百个点,不会超时。
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define L(t) t<<1
#define R(t) t<<1|1
#define eps 1e-7
typedef long long LL;
const int INF=1000000010;
const int maxn=305;
const int maxm=400005;
const int MOD=1000000007;
bool mark[maxn];
int mp[maxn][maxn];
int n,m,q,ma;
void spfa(int u)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(mp[i][u]<ma&&mp[u][j]<ma)
{
mp[i][j]=min(mp[i][j],mp[i][u]+mp[u][j]);
}
}
}
}
int main()
{
// freopen("in.txt","r",stdin);
int u,v,w,ca=1;
int fa,fb;
while(~scanf("%d%d%d",&n,&m,&q),n+m+q)
{
memset(mp,0x3f,sizeof(mp));
memset(mark,0,sizeof(mark));
ma=mp[0][0];
for(int i=0;i<n;i++)
mp[i][i]=0;
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
if(mp[u][v]>w)
mp[u][v]=w;
}
if(ca!=1)
printf("\n");
printf("Case %d:\n",ca++);
for(int i=0;i<q;i++)
{
scanf("%d%d",&u,&v);
if(!u)
{
if(mark[v])
printf("ERROR! At point %d\n",v);
else
{
mark[v]=1;
spfa(v);
}
}
else
{
scanf("%d",&u);
if(!mark[u]||!mark[v])
{
printf("ERROR! At path %d to %d\n",v,u);
}
else
{
if(mp[v][u]>=ma)
{
printf("No such path\n");
}
else
{
printf("%d\n",mp[v][u]);
}
}
}
}
}
return 0;
}