//* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include // #include using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; int popcount(ll t) { return __builtin_popcountll(t); } // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(25); } } setup_io; const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' const int N = 2011; vii G(N); //�񕔃O���t���ǂ����𔻒f bool bipartite() { stack st; vi color(N, -1); color[0] = 0; st.push(0); int i, j; while (!st.empty()) { i = st.top(); st.pop(); for (j = 0; j < G[i].size(); j++) { if (color[G[i][j]] == color[i]) { //cout << "NO" << endl; return false; } else { if (color[G[i][j]] == -1) { color[G[i][j]] = 1 - color[i]; st.push(G[i][j]); } } } } //cout << "YES" << endl; return true; } class UnionFind { public: int n; vi par; //�e vi ran; //�؂̐[�� vi num; //�v�f�� int g; // group�� UnionFind(int _n) { n = _n; g = n; par.resize(n); ran.resize(n); num.resize(n); for (int i = 0; i < n; i++) { par[i] = i; ran[i] = 0; num[i] = 1; } } //�؂̍������߂� int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } //x��y�̑�����W���𕹍� void unite(int x, int y) { x = find(x); y = find(y); int numsum = num[x] + num[y]; if (x == y) { return; } if (ran[x]> n >> d; UnionFind uf(n); rep (i, n) { rep (j, n) { char c; cin >> c; if (c == '1') { G[i].push_back(j); uf.unite(i, j); } } } if (uf.g != 1) { No(); return 0; } if (bipartite()) { No(); return 0; } if (d > 3 * n + 10) { Yes(); return 0; } using bit = bitset<2000>; vector> visited(d + 1, vector(n)); rep (i, n) visited[0][i][i] = true; rep (i, d) { rep (u, n) { if (i + 2 <= d) { visited[i + 2][u] |= visited[i][u]; } if (i >= 2) { if (visited[i][u] == visited[i - 2][u]) continue; } for (int v: G[u]) { visited[i + 1][v] |= visited[i][u]; } } } bit ful; rep (i, n) ful[i] = true; rep (i, n) { if (visited[d][i] != ful) { No(); return 0; } } Yes(); }