Submission #947919

# Submission time Handle Problem Language Result Execution time Memory
947919 2024-03-17T09:14:07 Z Darren0724 Newspapers (CEOI21_newspapers) C++17
0 / 100
6 ms 11368 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
vector<int> adj[N],vis(N),a[N];

void dfs(int k,int pa,int deep){
    vis[k]=1;
    a[k].push_back(deep);
    for(int j:adj[k]){
        if(j==pa)continue;
        dfs(j,k,deep+1);
        a[k].push_back(a[j][0]);
    }
    sort(all(a[k]),greater<int>());
}
int32_t main() {
    LCBorz;
    int n,m;cin>>n>>m;
    if(m>=n){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    if(n==1){
        cout<<"1\n1\n";
        return 0;
    }
    if(n==2){
        cout<<"2\n1 1\n";
        return 0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            a[i].clear();
        }
        dfs(i,i,0);
        if(a[i].size()<3){
            continue;
        }
        if(a[i][2]>=3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES\n1\n1";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Incorrect 4 ms 11368 KB Expected integer, but "YES" found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11356 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Incorrect 4 ms 11356 KB Expected integer, but "YES" found
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Incorrect 4 ms 11368 KB Expected integer, but "YES" found
4 Halted 0 ms 0 KB -