#include "bits/stdc++.h"
#include "closing.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define pb push_back
#define s second
#define f first
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
const int N=2e5+10;
ll k, c[N], d[N][2];
vector<pii> ad[N];
bool v[N][2];
int n, x, y;
int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N; x=X; y=Y; k=K;
FOR(i, 0, n) {
c[i]=d[i][0]=d[i][1]=v[i][0]=v[i][1]=0;
ad[i].clear();
}
FOR(i, 0, n-1) {
ad[U[i]].pb({V[i],W[i]});
ad[V[i]].pb({U[i],W[i]});
}
int ans=2;
v[x][0]=v[y][1]=true;
vi a, b; a.pb(x); b.pb(y);
while(true) {
ll mn=1e18, mn_in=-1;
for(auto it : a) {
for(auto [u, w] : ad[it]) {
if(!v[u][0]) {
ll now=d[it][0]+w-c[u];
if(mn>now) {
mn=now;
mn_in=u;
}
}
}
}
ll mn2=1e18, mn_in2=-1;
for(auto it : b) {
for(auto [u, w] : ad[it]) {
if(!v[u][1]) {
ll now=d[it][1]+w-c[u];
if(mn2>now) {
mn2=now;
mn_in2=u;
}
}
}
}
// cout << mn << " " << mn2 << ":\n";
// for(auto it : a) cout << it << " ";
// cout << endl;
// for(auto it : b) cout << it << " ";
// cout << endl;
if(mn_in==-1 && mn_in2==-1) break;
if(mn<=mn2) {
if(mn>k) break;
k-=mn;
d[mn_in][0]=mn+c[mn_in];
v[mn_in][0]=true;
c[mn_in]+=mn;
a.pb(mn_in);
}
else if(mn>mn2) {
if(mn2>k) break;
k-=mn2;
d[mn_in2][1]=mn2+c[mn_in2];
v[mn_in2][1]=true;
c[mn_in2]+=mn2;
b.pb(mn_in2);
}
else assert(false);
ans++;
}
// FOR(i, 0, n) {
// cout << c[i] << " ";
// }
return ans;
}
/*
1
7 0 2 10
0 1 2
0 3 3
1 2 4
2 4 2
2 5 5
5 6 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
25684 KB |
Output is correct |
2 |
Correct |
73 ms |
25392 KB |
Output is correct |
3 |
Correct |
35 ms |
10068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5152 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5152 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
4952 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5156 KB |
Output is correct |
21 |
Correct |
3 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
5152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4952 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5152 KB |
Output is correct |
9 |
Correct |
2 ms |
4952 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
4952 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5156 KB |
Output is correct |
21 |
Correct |
3 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
5152 KB |
Output is correct |
25 |
Correct |
3 ms |
5464 KB |
Output is correct |
26 |
Correct |
34 ms |
5460 KB |
Output is correct |
27 |
Correct |
3 ms |
5212 KB |
Output is correct |
28 |
Correct |
32 ms |
5468 KB |
Output is correct |
29 |
Correct |
33 ms |
5468 KB |
Output is correct |
30 |
Correct |
3 ms |
5220 KB |
Output is correct |
31 |
Correct |
8 ms |
5448 KB |
Output is correct |
32 |
Correct |
11 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
5152 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
5152 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5156 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5152 KB |
Output is correct |
26 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
5152 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5156 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5152 KB |
Output is correct |
26 |
Correct |
3 ms |
5464 KB |
Output is correct |
27 |
Correct |
34 ms |
5460 KB |
Output is correct |
28 |
Correct |
3 ms |
5212 KB |
Output is correct |
29 |
Correct |
32 ms |
5468 KB |
Output is correct |
30 |
Correct |
33 ms |
5468 KB |
Output is correct |
31 |
Correct |
3 ms |
5220 KB |
Output is correct |
32 |
Correct |
8 ms |
5448 KB |
Output is correct |
33 |
Correct |
11 ms |
5212 KB |
Output is correct |
34 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
5152 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5156 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
5152 KB |
Output is correct |
26 |
Correct |
3 ms |
5464 KB |
Output is correct |
27 |
Correct |
34 ms |
5460 KB |
Output is correct |
28 |
Correct |
3 ms |
5212 KB |
Output is correct |
29 |
Correct |
32 ms |
5468 KB |
Output is correct |
30 |
Correct |
33 ms |
5468 KB |
Output is correct |
31 |
Correct |
3 ms |
5220 KB |
Output is correct |
32 |
Correct |
8 ms |
5448 KB |
Output is correct |
33 |
Correct |
11 ms |
5212 KB |
Output is correct |
34 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
35 |
Halted |
0 ms |
0 KB |
- |