题目大意:给定一张无向图,求s1到t1与s2到t2的最长公共最短路
以s1 t1 s2 t2为源做4次最短路
如果某条有向边满足s到起始点的距离+边长+终点到t的距离=s到t的最短路 那么这条边就可以在s到t的最短路上
我们把所有既在s1到t1的最短路上也在s2到t2的最短路上的有向边都拎出来
容易证明这个图一定没有环 因此拓扑排序求最长链即可
写完发现过不去样例。。。
因为这题题目描述与题意不符,两个人从不同方向走同一条边也算满足条件。。。
于是我们把s2和t2反转之后再做一遍即可。。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 1510
using namespace std;
struct abcd{
int to,f,next;
}table[M*M<<1];
int head[M],_head[M],tot;
int n,m,s1,t1,s2,t2,ans;
int f1[M],g1[M],f2[M],g2[M];
int degree[M];
void Add(int head[],int x,int y,int z)
{
table[++tot].to=y;
table[tot].f=z;
table[tot].next=head[x];
head[x]=tot;
}
void SPFA(int f[],int S)
{
static int q[65540];
static bool v[M];
static unsigned short r,h;
int i;
memset(f,0x3f,sizeof(int)*M);
f[S]=0;q[++r]=S;
while(r!=h)