1 条题解

  • 0
    @ 2025-2-26 23:56:59
    // https://dashoj.com/p/131
    #include <bits/stdc++.h>
    
    using namespace std;
    int n;
    map<int, vector<int>> tree;
    
    void bfs() {
    	queue<int> q;
    	q.push(1);
    	while (!q.empty()) {
    		int x = q.front();
    		q.pop();
    		cout << x << ' ';
    		for (int i: tree[x]) q.push(i);
    	}
    }
    
    int main() {
    	cin >> n;
    	for (int i = 1; i < n; i++) {
    		int x, y;
    		cin >> x >> y;
    		tree[x].push_back(y);
    	}
    	bfs();
    	return 0;
    }
    

    信息

    ID
    131
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    35
    已通过
    19
    上传者