Written by @Yusif_M
In this problem we have to find if graph has repeated edge or not. If there is repeated edge then return YES, otherwise NO. The best and easiest way to solve this problem is to use . Inside the set we'll store the nodes of edges. If set's size is different than m, then there is repeated edge so we'll output YES , if they are equal then there is no repeated edge so we'll output NO. Here is the implementation of the algorithm in C++:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <string>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <unordered_set>
#define ll long long
#define ld long double
#define db double
#define ch char
#define sg string
#define st set
#define stck stack
#define pq priority_queue
#define dq deque
#define vc vector
#define bl bool
#define mp map
#define cp cout.precision
#define ts to_string
#define mst multiset
#define uost unordered_set
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,m,num1,num2;
scanf("%lld %lld",&n,&m);
st<pair<ll,ll>>nums;
for(int i=0;i<m;i++)
{
scanf("%lld %lld",&num1,&num2);
nums.insert({num1,num2}); //add nodes to set
}
if(m!=nums.size()) //if size is not equal to m then there is a removed edge
{
printf("YES");
}
else //if they're equal then no edge is repeated
{
printf("NO");
}
}