根付き木への変換
根とみなした頂点からBFSで構成していく。
code:cpp
using namespace std;
using Graph = vector<vector<int>>;
Graph ConvertRootedTree(Graph &Tree, int root) {
int size = Tree.size();
Graph RootedTree(size);
vector<bool> seen(size, false);
queue<int> que;
que.push(root);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto child : Treev) { RootedTreev.push_back(child); que.push(child);
}
}
return RootedTree;
}
int main() {
int n;
cin >> n;
Graph Tree(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
}
Graph RootedTree = ConvertRootedTree(Tree, 0);
return 0;
}