Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #define push_back pb
- #include <vector>
- #include <iostream>
- using namespace std;
- int cycle = -1;
- vector<int> g[100005];
- bool visited[100005];
- void dfs(int v, int parent = -1) {
- visited[v] = 1;
- for (int i=0; i < g[v].size(); i++) {
- if (g[v][i] == parent) {
- continue;
- }
- else if (visited[g[v][i]] == 0) {
- dfs(g[v][i], v);
- }
- else if (visited[g[v][i]] == 1) {
- cycle = 1;
- }
- }
- visited[v] = 2;
- }
- int tot = 0;
- int main() {
- int x;
- cin >> x;
- int tot = 0;
- for (int i=0; i < x; i++) {
- for (int j=0; j < x; j++) {
- int z;
- cin >> z;
- if (z==1) {
- tot += 1;
- g[i].pb(j);
- g[j].pb(i);
- }
- }
- }
- dfs(0);
- int vis = 0;
- for (int i=0; i < 1000; i++) {
- if (visited[i]) { vis += 1; }
- }
- for (int i=0; i < x; i++) {
- memset(visited, 0, sizeof(visited));
- dfs(i);
- }
- if (cycle == 1) {
- cout << 123 << endl;
- }
- if (tot == 2*(x-1) && vis == x) {
- cout << "YES" << endl;
- }
- else {
- cout << "NO" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment