-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Cowardly_Rooks.cpp
68 lines (53 loc) · 1.42 KB
/
A_Cowardly_Rooks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TestCases int TOTALTC ; cin >> TOTALTC ; for(_case = 1 ; _case <= TOTALTC ; _case++)
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin() , (x).end()
#define nl "\n"
int _case = 1 ;
void solve()
{
int n; cin >> n;
int m ; cin >> m ;
vector<int> row(n) , col(n) ;
vector<vector<int>> v (n,vector<int>(n)) ;
while(m--)
{
int x , y ; cin >> x >> y ;
x-- , y-- ;
v[x][y]++ ;
row[x]++ ;
col[y]++ ;
}
for(int i =0 ; i < n ;i++)
{
for(int j = 0 ; j < n ; j++)
{
int& curr = v[i][j] ;
if(curr > 0)
{
// col[j]-- ;
// row[i]-- ;
bool found = 0 ;
for(int k = 0 ; k < n ; k++)
{
if(row[k]==0 and i!=i)
{
found = 1 ;
cout << "YES" << nl ;
return ;
}
if(col[k]==0 and k!=j)
{
found = 1 ;
cout << "YES" << nl ;
return ;
}
}
}
}
}
cout << "NO" << nl ;
}
signed main(){ FAST TestCases solve() ; }