-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge Existence.cpp
More file actions
67 lines (62 loc) · 1.44 KB
/
Edge Existence.cpp
File metadata and controls
67 lines (62 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//Edge Existence
//You have been given an undirected graph consisting of N nodes and M edges.
//This graph can consist of self-loops as well as multiple edges. In addition , you have also been given Q queries.
//For each query , you shall be given 2 integers A and B. You just need to find if there exists an edge between node A and node B.
//If yes, print "YES" (without quotes) else , print "NO"(without quotes).
//
//Input Format:
//
//The first line consist of 2 integers N and M denoting the number of nodes and edges respectively.
//Each of the next M lines consist of 2 integers A and B denoting an undirected edge between node A and B.
//The next line contains a single integer Q denoting the number of queries.
//The next Line contains 2 integers A and B denoting the details of the query.
//
//Output Format
//
//Print Q lines, the answer to each query on a new line.
//
//Constraints:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
vector <int> a[1000];
for(int i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
a[x].push_back(y);
}
int q;
cin>>q;
while(q!=0)
{
int x,y,flag=0;
cin>>x>>y;
for(int i=0;i<a[x].size();i++)
{
if(a[x].at(i)==y)
{
cout<<"YES\n";
flag=1;
break;
}
}
if (flag==0)
{
cout<<"NO\n";
}
q--;
}
}
//4
//5
//1 2
//2 4
//3 1
//3 4
//4 2
//5
//1 2