blob: 7a1be5b14e39aec97da82047cc6be2a4f924f111 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
vector<vector<int>> adj;
map<vector<int>, int> known;
int treeLabel(int root, int p = -1) {
vector<int> children;
for (int x : adj[root]) {
if (x == p) continue;
children.push_back(treeLabel(x, root));
}
sort(all(children));
if (known.find(children) == known.end()) {
known[children] = sz(known);
}
return known[children];
}
|