이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100'005;
vector<array<int, 2>> adj[N];
vector<ll> v[N];
vector<ll> cur;
bool dfs(int i, int par, int dest) {
if (i == dest) return 1;
for (auto [nxt, idx] : adj[i]) {
if (nxt == par) continue;
for (auto x : v[idx]) {
cur.push_back(x);
}
if (dfs(nxt, i, dest)) {
return 1;
}
for (auto x : v[idx]) {
cur.pop_back();
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0, U, V; i < n - 1; i++) {
cin >> U >> V;
adj[U].push_back({V, i + 1});
adj[V].push_back({U, i + 1});
}
for (int i = 0; i < m; i++) {
ll p, c;
cin >> p >> c;
v[p].push_back(c);
}
while (q--) {
cur.clear();
int s, t;
ll x, y;
cin >> s >> t >> x >> y;
dfs(s, 0, t);
sort(cur.begin(), cur.end());
x -= cur.size();
for (int i = 0; i < cur.size(); i++) {
if (y - cur[i] >= 0) {
y -= cur[i];
x++;
} else {
break;
}
}
cout << max(x, (ll)-1) << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
currencies.cpp: In function 'bool dfs(int, int, int)':
currencies.cpp:19:13: warning: unused variable 'x' [-Wunused-variable]
19 | for (auto x : v[idx]) {
| ^
currencies.cpp: In function 'int main()':
currencies.cpp:47:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < cur.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |