建图
Time Limit: 1000 ms
Memory Limit: 65536 KiB
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
Hint
Source
xry-fhf
#include <stdio.h> #include <stdlib.h> int main() { int n, m, i, j, x, y, a[1005][1005]; while(~scanf("%d%d",&n,&m)) { for(i=0; i<n; i++) { for(j=0; j<n; j++) { a[i][j]=0; } } for(i=0; i<m; i++) { scanf("%d%d",&x,&y); a[x-1][y-1]=1; } for(i=0; i<n; i++) { for(j=0; j<n; j++) { if(j==n-1)printf("%d\n",a[i][j]); else printf("%d ",a[i][j]); } } } return 0; }