#include "closing.h"
#include <bits/stdc++.h>
// #include <vector>
using namespace std;
using ll = long long;
/*
Subtask 1 :
*/
class Subtask1
{
public:
vector<vector<pair<int, ll>>> adj;
vector<bool> vis;
void DFS(int u, int dd, vector<ll> &dist)
{
vis[u] = 1;
dist[u] = dd;
for (auto [v, w] : adj[u])
{
if (vis[v])
continue;
DFS(v, dd + w, dist);
}
}
int getsol(int N, int X, int Y, long long K,
vector<int> U, vector<int> V, vector<int> W)
{
adj.resize(N, vector<pair<int, ll>>());
for (int i = 0; i < N - 1; i++)
{
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
}
vector<ll> dist(N);
vis.assign(N, 0);
DFS(X, 0, dist);
vector<ll> dist2(N);
vis.assign(N, 0);
DFS(Y, 0, dist2);
dist.insert(dist.end(), dist2.begin(), dist2.end());
sort(dist.begin(), dist.end());
int pt = 0, ans = 0;
ll cost = 0;
while (cost + dist[pt] <= K && pt < dist.size())
{
cost += dist[pt];
pt++;
ans++;
}
return ans;
}
};
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
Subtask1 sub1;
return sub1.getsol(N, X, Y, K, U, V, W);
}
Compilation message
closing.cpp: In member function 'int Subtask1::getsol(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:48:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | while (cost + dist[pt] <= K && pt < dist.size())
| ~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
149 ms |
30416 KB |
1st lines differ - on the 1st token, expected: '451', found: '400000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |