正文
增加 3 行删除 3 行
74 行未改动7576777879808182838485868788899091929394953 行未改动74 行未改动{ios::sync_with_stdio(false);cin.tie(0);int n, m, root;cin >> n >> m >> root;for (int i = 1, x, y; i < n; ++i)cin >> x >> y, edge[x].push_back(y), edge[y].push_back(x);dfs(root, -1);for (int i = 1; i <= log2n; ++i)for (int j = 1; j + (1 << i) - 1 <= n; ++j)st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);while (m--){int u, v;cin >> u >> v;cout << lca(u, v) << "\n";}return 0;3 行未改动74 行未改动7576777879808182838485868788899091929394953 行未改动74 行未改动{ios::sync_with_stdio(false);cin.tie(0);int n, m, root;cin >> n >> m >> root;for (int i = 1, x, y; i < n; ++i)cin >> x >> y, edge[x].push_back(y), edge[y].push_back(x);dfs(root, -1);for (int i = 1; i <= log2n; ++i)for (int j = 1; j + (1 << i) - 1 <= n; ++j)st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);while (m--){int u, v;cin >> u >> v;cout << lca(u, v) << "\n";}return 0;3 行未改动