#include "closing.h"
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) ll(x.size())
#define ff first
#define ss second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAX=1e6;
const ll mod=1e9+7;
ll distx[MAX], disty[MAX];
vector<ii>gfo[MAX];
vector<ii> ans;
bool vst[MAX];
void dfsx(int u, int f){
for(auto x:gfo[u]){
int v=x.ff;
ll w1=x.ss;
if(v!=f){
distx[v]=distx[u]+w1;
dfsx(v,u);
}
}
return;
}
void dfsy(int u, int f){
for(auto x:gfo[u]){
int v=x.ff;
ll w1=x.ss;
if(v!=f){
disty[v]=disty[u]+w1;
dfsy(v,u);
}
}
return;
}
void clen(int n){
ans.clear();
for(int i=0; i<=n; i++){
gfo[i].clear();
distx[i]=0;
disty[i]=0;
vst[i]=0;
}
return;
}
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W){
for(ll i=0; i<sz(U) ; i++){
gfo[U[i]].pb({V[i],W[i]});
gfo[V[i]].pb({U[i],W[i]});
}
dfsx(X,X);
dfsy(Y,Y);
for(int i=0; i<N; i++){
ans.pb({distx[i], i});
ans.pb({disty[i], i});
}
sort(all(ans));
ll cont=0, sum=0;
for(auto x:ans){
if(!vst[x.ss]){
sum+=x.ff;
vst[x.ss]=true;
}
else{
sum+=abs(distx[x.ss]-disty[x.ss]);
}
if(sum<=K)cont++;
else break;
}
clen(N);
return cont;
}
// int main(){
// int N, X, Y, K;
// vector<int> U, V, W;
// max_score(N,X,Y,K,U,V,W);
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
85 ms |
48620 KB |
1st lines differ - on the 1st token, expected: '451', found: '207219' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
3 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
25176 KB |
Output is correct |
4 |
Correct |
3 ms |
24924 KB |
Output is correct |
5 |
Correct |
3 ms |
25068 KB |
Output is correct |
6 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
3 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
25176 KB |
Output is correct |
4 |
Correct |
3 ms |
24924 KB |
Output is correct |
5 |
Correct |
3 ms |
25068 KB |
Output is correct |
6 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24924 KB |
Output is correct |
2 |
Correct |
3 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
25176 KB |
Output is correct |
4 |
Correct |
3 ms |
24924 KB |
Output is correct |
5 |
Correct |
3 ms |
25068 KB |
Output is correct |
6 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
24924 KB |
Output is correct |
4 |
Correct |
3 ms |
25176 KB |
Output is correct |
5 |
Correct |
3 ms |
24924 KB |
Output is correct |
6 |
Correct |
3 ms |
25068 KB |
Output is correct |
7 |
Incorrect |
4 ms |
24924 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
24924 KB |
Output is correct |
4 |
Correct |
3 ms |
25176 KB |
Output is correct |
5 |
Correct |
3 ms |
24924 KB |
Output is correct |
6 |
Correct |
3 ms |
25068 KB |
Output is correct |
7 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
24924 KB |
Output is correct |
4 |
Correct |
3 ms |
25176 KB |
Output is correct |
5 |
Correct |
3 ms |
24924 KB |
Output is correct |
6 |
Correct |
3 ms |
25068 KB |
Output is correct |
7 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
24924 KB |
Output is correct |
4 |
Correct |
3 ms |
25176 KB |
Output is correct |
5 |
Correct |
3 ms |
24924 KB |
Output is correct |
6 |
Correct |
3 ms |
25068 KB |
Output is correct |
7 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
24924 KB |
Output is correct |
2 |
Correct |
4 ms |
24924 KB |
Output is correct |
3 |
Correct |
3 ms |
24924 KB |
Output is correct |
4 |
Correct |
3 ms |
25176 KB |
Output is correct |
5 |
Correct |
3 ms |
24924 KB |
Output is correct |
6 |
Correct |
3 ms |
25068 KB |
Output is correct |
7 |
Incorrect |
4 ms |
24920 KB |
1st lines differ - on the 1st token, expected: '96', found: '93' |
8 |
Halted |
0 ms |
0 KB |
- |