// 模拟链表
#include <iostream>
#include <vector>
using namespace std;
#define MAXN 5002
vector<int> adj[MAXN];
int main() {
int n, m; cin >> n >> m;
while(m--){
int x, y; cin >> x >> y;
adj[x].push_back(y); adj[y].push_back(x);
}
for (int i = 1; i <= n; i++) {
cout << adj[i].size() << ' ';
for (auto x : adj[i]) {
cout << x << ' ';
}
cout << endl;
}
return 0;
}模拟链表
文章信息与版本
文章信息
- 发布
- 2025年6月28日
- 收录
- 2025年12月12日
- 更新
- 2026年11月15日
- 篇幅
- 约 1 分钟