#include<bits/stdc++.h>
using namespace std;
int n,m;
int edge[1005][1005];
vector<int> e[1005];
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
edge[u][v]=1;
edge[v][u]=1;
e[u].push_back(v);
e[v].push_back(u);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<edge[i][j]<<" ";
}
cout<<"\n";
}
for(int i=1;i<=n;i++){
cout<<e[i].size()<<" ";
sort(e[i].begin(),e[i].end());
for(int j=0;j<e[i].size();j++){
cout<<e[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
洛谷B3643 图的存储
最新推荐文章于 2024-06-09 20:29:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)