Skip to content

Commit 917df58

Browse files
authored
Add files via upload
1 parent 52ceacc commit 917df58

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
int main() {
6+
int n;//number of vertices
7+
int m;//number of edges
8+
cin>>n>>m;
9+
int i;
10+
vector<int> v[n+1];
11+
for(i=0;i<m;i++)
12+
{
13+
int x,y;
14+
cin>>x>>y;//input the vertices which are connected
15+
v[x].push_back(y); //put the vertex y in the list of x
16+
v[y].push_back(x); // put the vertex x in the list of y
17+
}
18+
int q;
19+
cin>>q;// queries to check whether a edge exist or not
20+
while(q--)
21+
{
22+
int x,y;
23+
cin>>x>>y;//check whether edge between x or y exist or not
24+
int flg=-1;
25+
for(i=0;i<v[x].size();i++)
26+
{if(v[x][i]==y)
27+
{
28+
flg=1;break;
29+
}
30+
31+
}
32+
if(flg==1)
33+
cout<<"Edge exist\n";
34+
else
35+
cout<<"Edge does not exist\n";
36+
}
37+
return 0;
38+
}

0 commit comments

Comments
 (0)