Problem Description
编程使得程序可以接受一个图的点边作为输入,然后显示出这个图。
Input
多组测试数据,对于每组测试数据,第一行输入正整数n(1 <= n <= 1000)和m,之后m行输入正整数x、y,表示在点x和点y之间存在有向边相连。
Output
对于每组测试数据,输出图的关系矩阵。
Sample Input
4 5 1 1 2 2 2 4 3 3 4 4
Sample Output
1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1
#include <stdlib.h>
#include <string.h>
int main()
{
int a[1001][1001];
int m,i,j,n,x,y;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,0,sizeof(a));
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
a[x][y]=1;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(j==n) printf("%d\n",a[i][j]);
else printf("%d ",a[i][j]);
}
}
}
return 0;
}