# CF915D Almost Acyclic Graph 拓扑排序

### 题面

$n<= 500, m <= min(n(n - 1), 10^5)$

### 题解

#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 600
#define ac 101000

int n, m;
int in[AC], s[AC];

{
int x = 0;char c = getchar();
while(c > '9' || c < '0')  c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}

inline void add(int f, int w){//加单项边
date[++ tot] = w, Next[tot] = Head[f], Head[f] = tot, in[w] ++, s[w] ++;
}

void pre()
{
for(R i = 1; i <= m; i ++)
{
}
}

bool t_sort()
{
head = 1, tail = 0;
for(R i = 1; i <= n; i ++)
if(!in[i]) q[++ tail] = i;
{
for(R i = Head[x]; i; i = Next[i])
{
int now = date[i];
if(!(-- in[now])) q[++ tail] = now;
}
}
return tail == n;
}

void work()
{
for(R i = 1; i <= n; i ++)
{
if(!in[i]) continue;
-- in[i];
if(t_sort())
{
printf("YES\n");
return ;
}
memcpy(in, s, (n + 1) * 4);
//    for(R j = 1; j <= n; j ++) in[j] = s[j];
}
printf("NO\n");
}

int main()
{
//	freopen("in.in", "r", stdin);
pre();
work();
return 0;
}

posted @ 2021-10-14 00:06  ww3113306  阅读(13)  评论(0编辑  收藏  举报