-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon Subsequence.cpp
More file actions
50 lines (39 loc) · 928 Bytes
/
Common Subsequence.cpp
File metadata and controls
50 lines (39 loc) · 928 Bytes
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
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t; cin>>t;
for(int z=0; z<t; z++)
{
int a,b; cin>>a>>b;
vector<int> v1, v2;
for(int i=0; i<a; i++){
int x; cin>>x;
v1.push_back(x);
}
for(int i=0; i<b; i++){
int x; cin>>x;
v2.push_back(x);
}
bool flag = false;
int r;
for(int i=0; i<v2.size(); i++)
{
for(int j=0; j<v1.size(); j++)
{
if(v2[i]==v1[j])
{
r = v2[i];
flag = true;
break;
}
}
if(flag==true) break;
}
if(flag==true) cout<<"YES"<<endl<<"1 "<<r<<endl;
else cout<<"NO"<<endl;
}
}