ll mul(ll a, ll b){ return __int128(a) * b % mod; }
voidsolve(){ int n; std::cin >> n; ll base = rng() % 1000000000 + 234567; std::vector<int> cnt(n + 1, 0); std::vector<ll> p(n + 1, 1); for(int i = 1; i <= n; i++){ p[i] = mul(p[i - 1], base); }
for(int i = 1; i <= n - 1; i++){ int x; std::cin >> x; if(x <= n) cnt[x] += 1; } std::vector<std::vector<int>> vec(n + 1); for(int i = 1; i <= n - 1; i++){ int x, y; std::cin >> x >> y; vec[x].push_back(y); vec[y].push_back(x); //std::cerr << x << space << y << endl; }
ll now = 0; for(int i = n; i >= 0; i--){ now = mul(now, base); now += cnt[i]; } std::set<ll> win; for(int i = n; i >= 0; i--){ ll res = p[i]; win.insert((res + now) % mod); }