제출 #1191202

#제출 시각아이디문제언어결과실행 시간메모리
1191202user192837Newspapers (CEOI21_newspapers)C++17
4 / 100
0 ms328 KiB
#include <bits/stdc++.h>
#define ar array
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;

const int N = 1005;
vector <int> g[N];
int vis[N], ok = 1;

void dfs(int x, int par) {
    vis[x] = 1;
    for (int y : g[x]) {
        if (y != par) {
            if (vis[y]) {
                ok = 0;
            } else {
                dfs(y, x);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs(1, 0);
    if (ok) {
        cout << "YES\n";
        cout << "1\n1";
    } else {
        cout << "NO\n";
    }
    return 0;
}

/*
if cycle -> NO
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...