P5663 加工零件
题目传送门
SPFA对于每个点是可多次出队入队的,so数组要开大些(检查40分钟 2个WA)
思路:
举个栗子:
7号工人做一个第5个阶段的零件,1号工人是否要做原材料?
可以看成7号工人到1号工人是否有路径为7的问题。
然后我们还要明白一条秘技:反复横跳
所以我们可以得出两个工人如果之间有一条路径为3,那么一定有5,7,9……
偶数同理
知道后,我们就可把问题化简为:求1到任何一个点的奇偶最短路。
还有个细节:
vis数组是要用二维分别记录奇偶的,不能只用一维。
1到任何一个点的奇数步所经过点,偶数时也是可以用的。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
using namespace std;
const int MAX=2147483647;
const int N=1e5+10;
struct node
{
int x,y,next;
} edge[2*N];
int n,m,q,que[N*10],jo[N*10],dis[N][2],tot,hd[N]