eolymp
bolt
Try our new interface for solving problems
Problems

Maximum Islands

published at 4/22/24, 7:13:12 pm

include <bits/stdc++.h>

define ll long long int

define ld long double

using namespace std; int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k, m;
cin>>n>>k;
m = (n*(n-1))/2;
if(k < m){
    cout<<"NO";
    return 0;
}
set<ll>s;
multiset<ll>ms;
for(int i = 0; i<k; i++){
    ll x, y;
    cin>>x>>y;
    s.insert(x);
    s.insert(y);
    ms.insert(x);
    ms.insert(y);
}
for(auto i = s.begin(); i!=s.end(); i++){
    ll x = *i;
    if(ms.count(x) < (n-1)){
        cout<<"NO";
        return 0;
    }
}
cout<<"YES";

} //TECHNOBLADE NEVER DIES