SDUT 3804 离散题目10

来源:互联网 发布:企业数据架构设计 编辑:程序博客网 时间:2024/06/05 22:33

Problem Description

让你证明集合A,B的函数关系是满射

Input

多组输入直到文件结束,对于每组输入,第一行先输入一个n(A集合里的元素个数),m(B集合里的元素个数),k(F数学函数关系的条数)。

0 < n,m < 10000, 0 < k < n;

第二行输入有n个元素,分别为a1到an;

第三行输入有m个元素,分别为b1到bn;

接下来输入有k行,分别为集合A到B的关系

Output

(一组答案占一行)

当满足满射关系时输出Yes。

不满足关系时输出No。

Example Input

5 3 5
1 3 5 7 8
2 5 6
1 2
3 6
5 5
7 2
8 6

Example Output

Yes

代码:

#include<bits/stdc++.h>using namespace std;int main(){    vector<int> a, b;    set<int> q, p;    int n, m, k, num, i, t, t1;    while(~scanf("%d %d %d", &n, &m, &k))    {        for(i = 0; i < n; i++)//集合A        {            scanf("%d", &num);            a.push_back(num);        }        for(i = 0; i < m; i++)//集合B        {            scanf("%d", &num);            b.push_back(num);        }        int num1;        for(i = 0; i < k; i++)        {            scanf("%d %d", &num, &num1);            q.insert(num);            p.insert(num1);        }        t = q.size();        t1 = p.size();        if(t == k && t1 == m)//全部元素都用上了,满足满射        {            printf("Yes\n");        }        else printf("No\n");        a.clear(), b.clear(), q.clear(), p.clear();    }    return 0;}
原创粉丝点击