题意
给定一张1e3的有向图,每条路径都有一个编码 (编码范围为20),并给出一些人类点,和目的点,求是否存在从非人类点出发到目的点的路径编号序与人类店出发到目标点的路径编码序一样。存在输出YES,否则NO
题解
倒着去考虑,假若存在一条一样的路那么从后往前回溯路径发现两条路径的起点都为目标点,终点一个为人类点,一个为非人类点,之后我们考虑两个状态代表人类和非人类,他们的出发点都为目标点,之后他们两两选择的路径需要保证路径编号一样,因此我们只要将所有可行的出发点塞入队列,跑bfs,最后check是否存在一个非人类点和一个人类点这样的状态是可达状态,若存在则YES,否则NO
代码
/**
* author: TelmaZzzz
* create: 2019-10-02-21.46.23
**/
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
void _R(int &x) {
scanf("%d", &x); }
void _R(ll &x) {
scanf("%lld", &x); }
void _R(db &x) {
scanf("%lf", &x); }
void _R(char &x) {
scanf(" %c", &x); }
void _R(char *x) {
scanf("%s", x); }
void R() {
}
template<class T, class... U> void R(T &head, U &... tail)