题解:CF1970C2 Game on Tree (Medium)
yr409892525 · · 题解
题解:CF1970C2 Game on Tree (Medium)
很明显,把起点当做根后。
每一步只能从父亲移动到儿子。
所以令
当
也就是若
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 2e5 + 5;
int n, m, d[kMaxN];
vector<int> e[kMaxN];
int s;
bool S(int x, int f) {
if (d[x] == -1) {
d[x] = 1;
for (int i : e[x]) {
(i != f) && (d[x] &= !S(i, x));
}
}
return d[x];
}
int main() {
cin >> n >> m;
fill(d + 1, d + n + 1, -1);
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
e[x].push_back(y), e[y].push_back(x);
}
cin >> s;
cout << (S(s, 0) ? "Hermione" : "Ron");
return 0;
}