mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 17:49:44 +08:00
d
This commit is contained in:
51
CodeForces/Chat Screenshots.cpp
Normal file
51
CodeForces/Chat Screenshots.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
const int N = 200005;
|
||||
struct Edge{
|
||||
int to, nxt;
|
||||
}g[N];
|
||||
int h[N], d[N], idx;
|
||||
int a[N], q[N];
|
||||
void add(int a,int b)
|
||||
{
|
||||
g[++idx].to = b, g[idx].nxt = h[a], h[a] = idx;
|
||||
d[b] ++;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n, k;
|
||||
scanf("%d%d", &n, &k);
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
h[i] = d[i] = 0;
|
||||
idx = 0;
|
||||
for (int i = 1;i <= k; i ++ )
|
||||
{
|
||||
for (int j = 1; j <= n; j ++ )
|
||||
scanf("%d", &a[j]);
|
||||
for (int j = 2; j < n; j ++ )
|
||||
add(a[j], a[j + 1]);
|
||||
}
|
||||
int hh = 0, tt = -1;
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
if (d[i] == 0)
|
||||
q[ ++ tt] = i;
|
||||
while (hh <= tt)
|
||||
{
|
||||
int t = q[hh ++];
|
||||
for (int i = h[t]; i; i = g[i].nxt)
|
||||
{
|
||||
int j = g[i].to;
|
||||
if ( -- d[j] == 0)
|
||||
q[ ++ tt] = j;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
if (d[i] > 0)
|
||||
{
|
||||
cout << "NO";
|
||||
return 0;
|
||||
}
|
||||
cout << "YES";
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user