离散题目13
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
DaYu平时只顾着看电影,没有学习离散,学期末快考试的时候才慌了神,因为时间不够,因此他决定只复习一个知识点,但是他发现他一个知识点都不会,因此他跑过来请你帮他解决一个问题。求一个集合是否是自反的。
Input
第一行输入组数T(T<10),每组的第一行输入集合元素个数m(m < 100)和对应关系个数n(n < 100),集合中元素为1,2,…,m,接下来n行每行输入两个数x,y(0 < x, y < 100)
Output
如果满足自反关系,则输出true,否则输出false。
Example Input
2 5 9 1 1 1 2 2 2 3 3 2 3 4 4 4 5 5 5 5 1 5 8 1 1 1 2 2 2 3 3 2 3 4 4 4 5 5 1
Example Output
true false
代码:
#include<iostream> using namespace std; int main() { int t; cin>>t; while(t--) { int m, n, i, x, y, count = 0; cin>>m>>n; for(i = 0;i<n;i++) { cin>>x>>y; if(x==y&&x<=m&&y<=m) count++; } if(count==m) cout<<"true"<<endl; else cout<<"false"<<endl; } }