题目:给你一张图,判断它的每个结点和所有结点是否有直接联系,如果有,输出1,否则输出0.
输入
3
1 2
1 3
2 3
输出
0 1 1
1 0 1
1 1 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int n;
int a[1010][1010];
int main()
{
freopen("change.in","r",stdin);
freopen("change.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
int x,y;
cin>>x>>y;
a[x][y]=a[y][x]=1;//本题是无向图,a[x][y]和a[y][x]互通,标记为1.
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}