【題解】Codeforces 1382A. Common Subsequence

【題目敘述】http://codeforces.com/contest/1382/problem/A

#include <iostream>
#include <set>
using namespace std;
 
int t, n, m, a;
set <int> st1, st2;
 
int main() {
    cin >> t;
    while (t--){
        cin >> n >> m;
        st1.clear();
        st2.clear();
        for (int i = 0; i < n; i++){
            cin >> a;
            st1.insert(a);
        }
        for (int i = 0; i < m; i++){
            cin >> a;
            st2.insert(a);
        }
        bool flag = false;
        for (int i = 1; i <= 1000; i++){
            if (st1.count(i) && st2.count(i)){
                flag = true;
                cout << "YES\n";
                cout << 1 << " " << i << "\n";
                break;
            }
        }
        if (!flag) cout << "NO\n";
    }
}
分享本文 Share with friends