Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <cstdio>
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- const int N = 110;
- int graph[N][N];
- int n;
- int colour[N];
- void dfs(int v) {
- for (int i = 0; i < n; i++) {
- int to = graph[v][i];
- if (to == 0) {
- continue;
- }
- if (colour[i] == -1) {
- colour[i] = 1 - colour[v];
- dfs(i);
- }
- }
- }
- bool possible() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (i == j) {
- continue;
- }
- if (graph[i][j] == 1 && colour[i] == colour[j]) {
- return false;
- }
- }
- }
- return true;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- scanf(" %d", &graph[i][j]);
- }
- }
- for (int i = 0; i < n; i++) {
- colour[i] = -1;
- }
- for (int i = 0; i < n; i++) {
- if (colour[i] == -1) {
- dfs(i);
- colour[i] = 0;
- }
- }
- if (possible()) {
- printf("YES");
- }
- else {
- printf("NO");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement