本题的提示要用拓扑
本人想着试着用拓扑,但是发现要求的数组太大,没法构建相应的边,故放弃了
因此想了另一个办法,代码如下
#pragma warning(disable:4996)
#include<stdio.h>
using namespace std;
#define maxn 1000001
int maxx;
struct listnode
{
listnode*pre;
int indu_num = 0;//记录indu指向的j,即i->j
listnode() {}
listnode(int n, listnode*p = NULL) :indu_num(n), pre(p) {}
};
struct p_list
{
listnode*head, *trail;
int flag = 1,length=1;
void init();
// ~p_list();
p_list() { init(); }
void insert(int&out);
// p_list&operator=(p_list&a);
};
void p_list::init()
{
head = new listnode();
trail = new listnode();
head->pre = trail;
trail->pre = NULL;
}
void p_list::insert(int&out)//越先进入的元素,越靠近队尾
{
listnode*p = new listnode(out);
p->pre = head->pre;
head->pre = p;
}
p_list edge[maxn];
int dsf(listnode*p, int i)//i是上一层的值
{
auto q = p->pre;
int count=1;
w