離散題目14
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
判斷集合是不是對稱的。
Input
首先輸入兩個數n,m表示集合中元素的個數,以及存在的關係數。
接下來1行包含n個以空格分隔的整數。
接下來m行,每行包含兩個數a,b表示關係。
(1< = n < = 1000,1 < = a,b < = n,m < = n*(n-1)&& m < = 1000)
Output
對於每組輸入,如果這個集合是對稱的則輸出“YES”,否則輸出“NO”。(均不包含引號)
Example Input
5 8
1 1
1 2
2 1
3 3
2 3
3 2
4 5
5 4
5 9
1 1
1 2
2 1
3 3
2 3
3 2
4 5
5 4
5 1
Example Output
YES
NO
include <stdio.h>
include <stdlib.h>
int a[1001][1001];
int main()
{
int w,e,n,m,i,j,q;
while(scanf("%d %d",&n,&m)!=EOF)
{
q=1;
for(i=0; i<m; i++)
{
scanf("%d %d",&w,&e);
a[w][e]=1;
}
for(i=0; i<=n; i++)
for(j=0; j<=n; j++)
{
if(a[i][j]==a[j][i])
continue;
else
{
q=0;
break;
}
}
if(q)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}