Skip to content

Instantly share code, notes, and snippets.

@anantbahuguna
Created May 6, 2020 07:34
Show Gist options
  • Save anantbahuguna/d505abdf9022c79396e633997251fbac to your computer and use it in GitHub Desktop.
Save anantbahuguna/d505abdf9022c79396e633997251fbac to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > vpairs;
int main()
{
//write your code here
int n,m;
cin>>n>>m;
while(m--)
{
int a,b;
cin>>a>>b;
vpairs.emplace_back(a,b);
}
for(int x: {vpairs[0].first,vpairs[0].second})
{
vector<int> val(n+1);
int all = 0;
for(auto c: vpairs)
{
if(c.first != x && c.second != x)
{
val[c.first]++;
val[c.second]++;
all++;
}
}
if(*max_element(val.begin(),val.end()) == all)
{
cout<<"YES\n";
return 0;
}
}
cout<<"NO\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment