이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
void dfs(long long x, long long p, vector<vector<pair<long long, long long>>> &AR, map<long long, long long> &dp, long long K, long long prof, long long prof2, long long &best)
{
map<long long, long long> M;
M[prof] = prof2;
for (long long i = 0; i < AR[x].size(); i++)
{
if (AR[x][i].first == p)
continue;
dfs(AR[x][i].first, x, AR, dp, K, prof + AR[x][i].second, prof2 + 1, best);
if (dp.size() > M.size())
swap(dp, M);
for (auto j : dp)
{
if (M[K - j.first + 2 * prof] > 0)
best = min(best, M[K - j.first + 2 * prof] + j.second - 2 * prof2);
else
M.erase(K - j.first + 2 * prof);
}
for (auto j : dp)
{
M[j.first] = 100000000;
M[j.first] = min(M[j.first], j.second);
}
}
swap(dp, M);
}
int best_path(int N, int K, int H[][2], int L[])
{
vector<vector<pair<long long, long long>>> AR(N);
for (long long i = 0; i < N - 1; i++)
{
AR[H[i][0]].push_back({H[i][1], L[i]});
AR[H[i][1]].push_back({H[i][0], L[i]});
};
map<long long, long long> dp;
long long best = 100000000;
dfs(0, 0, AR, dp, K, 1, 1, best);
return ((best == 100000000) ? -1 : (int)best);
}
/*long long main()
{
long long N, K;
cin >> N >> K;
long long L[N], H[N][2];
for (long long i = 0; i < N - 1; i++)
{
cin >> H[i][0] >> H[i][1];
}
for (long long i = 0; i < N - 1; i++)
{
cin >> L[i];
}
cout << best_path(N, K, H, L);
}*/
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'void dfs(long long int, long long int, std::vector<std::vector<std::pair<long long int, long long int> > >&, std::map<long long int, long long int>&, long long int, long long int, long long int, long long int&)':
race.cpp:8:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (long long i = 0; i < AR[x].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... |