이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M, Q;
cin >> N >> M >> Q;
vector<pair<int, int>> edges(N - 1);
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--, y--;
edges[i] = {x, y};
adj[x].emplace_back(y, i);
adj[y].emplace_back(x, i);
}
vector<vector<int>> c(N - 1);
for (int i = 0; i < M; i++) {
int P, C;
cin >> P >> C;
c[P - 1].push_back(C);
}
while (Q--) {
int S, T, X; ll Y;
cin >> S >> T >> X >> Y;
S--, T--;
vector<int> p(N, -1);
queue<int> q;
p[S] = S;
q.push(S);
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto [y, z] : adj[x]) {
if (p[y] == -1) {
p[y] = z;
q.push(y);
}
}
}
priority_queue<int, vector<int>, greater<int>> pq;
while (T != S) {
for (int v : c[p[T]]) {
pq.push(v);
}
auto [x, y] = edges[p[T]];
T ^= x ^ y;
}
while (!pq.empty() && pq.top() <= Y) {
Y -= pq.top();
pq.pop();
}
X -= pq.size();
X = max(X, -1);
cout << X << "\n";
}
return 6/22;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |