-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path11550-Demandingdilemma.cpp
executable file
·64 lines (56 loc) · 1.1 KB
/
11550-Demandingdilemma.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
//
// 11550 - Demanding dilemma.cpp
// Uva
//
// Created by Alexander Faxå on 2012-02-13.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
using namespace std;
int g[50][50];
int m, n;
bool ok(int x, int y)
{
int check = 0;
for(int j = 0; j < n; j++)
if(g[x][j] && g[y][j]){
if(check)
return false;
check = 1;
}
return true;
}
void solve()
{
for (int i = 0; i < m; i++) {
for (int j = i+1; j < m; j++) {
if(!ok(i, j)){
cout << "No" << endl;
return;
}
}
}
for (int j = 0; j < n; j++) {
int cnt = 0;
for(int i = 0; i < m; i++)
if(g[i][j])
cnt++;
if(cnt != 2){
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
int main(){
int t;
cin >> t;
while(t--){
cin >> m >> n;
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
cin >> g[i][j];
solve();
}
return 0;
}