ProgramAlgTrain/20240919/CSP常考算法模板/图的存储_vector.cpp

39 lines
436 B
C++
Raw Permalink Normal View History

2024-09-19 02:22:41 +00:00
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[101];
int main()
{
int n,m,x,y;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
//todo
graph[x].push_back(y);
graph[y].push_back(x);
}
for(int i=1;i<=n;i++)
{
//todo
// for(int j=0;j<graph[i].size();j++)
// {
// cout<<graph[i][j]<<" ";
// }
for(int j:graph[i])
{
cout<<j<<" ";
}
cout<<endl;
}
return 0;
}
/*
5 5
1 2
2 3
3 4
4 5
5 1
*/