답안 #1114579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114579 2024-11-19T08:12:54 Z vjudge1 Newspapers (CEOI21_newspapers) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#define pb push_back
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 998244353
#define MX 1005
using namespace std;

vi edges[MX];
int rdep[MX];
int dfs(int node, int pa){
    rdep[node]=0;
    int cnt=0;
    for(auto i:edges[node]){
        if(i==pa) continue;
        if(!dfs(i, node)) return 0;
        rdep[node]=max(rdep[node], rdep[i]+1);
        if(rdep[i]>1) cnt++;
        if(cnt>2) return 0;
    }
    return 1;
}

void solve(){
    int n,m; cin >> n >> m;
    for(int i=1; i<=m; i++){
        int a,b; cin >> a >> b;
        edges[a].pb(b);
        edges[b].pb(a);
    }
    if(m>=n){
        cout << "NO\n";
        return;
    }
    for(int r=1; r<=n; r++){
        if(!dfs(r, 0)){
            cout << "NO\n";
            return;
        }
    }
    cout << "YES\n";
    cout << 0 << endl;
}


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    /*#else
    freopen("248.in","r",stdin);
    freopen("248.out","w",stdout);*/
    #endif


    int t=1;
    //cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Integer parameter [name=k] equals to 0, violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Integer parameter [name=k] equals to 0, violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Integer parameter [name=k] equals to 0, violates the range [1, 5]
2 Halted 0 ms 0 KB -