fork download
  1. #include <cmath>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <algorithm>
  8. #include <queue>
  9.  
  10. #define rep(i, l, r) for(int i = l; i <= r; i++)
  11. #define down(i, l, r) for(int i = l; i >= r; i--)
  12. #define MS 456
  13. #define MAX 1037471823
  14. #define Q 103
  15.  
  16. using namespace std;
  17.  
  18. int t, n, m[MS][MS], k[MS], a;
  19. bool u[MS];
  20.  
  21. bool Find(int x)
  22. {
  23. rep(i, 1, n) if (m[x][i] == 1 && !u[i])
  24. {
  25. u[i] = 1;
  26. if (k[i] == 0 || Find(k[i])) { k[i] = x; return true; }
  27. }
  28. return false;
  29. }
  30.  
  31. int main()
  32. {
  33. scanf("%d", &t);
  34. while (t-- > 0)
  35. {
  36. scanf("%d", &n);
  37. rep(i, 1, n) rep(j, 1, n) scanf("%d", &m[i][j]);
  38. rep(i, 1, n) k[i] = 0; a = 1;
  39. while (a <= n)
  40. {
  41. memset(u, 0, sizeof(u));
  42. if (Find(a)) a++; else break;
  43. }
  44. if (a <= n) printf("No\n"); else printf("Yes\n");
  45. }
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 4156KB
stdin
1
3
0 1 0
1 0 1
0 0 1
stdout
Yes