#include <bits/stdc++.h>
#include "closing.h"
#define ll long long
#define N 200005
#define sz(s) (int)s.size()
#define ff first
#define ss second
using namespace std;
vector <pair<int,int>> v[N];
ll a[5][N], b[5][N], c[N], d1[N], d2[N], x2, y2, vis[N];
map <pair<int,int>, int> m;
void dfs(int z, int z1){
for(auto i : v[z]){
if(a[z1][i.ff] == 0){
a[z1][i.ff] = z;
dfs(i.ff, z1);
}
}
}
ll df(int z, int z1){
if((z == x2 and z1 == 1) or (z == y2 and z1 == 2)) return 0;
return (c[a[z1][z]] - (m[{a[z1][z],z}]) + df(a[z1][z], z1));
}
void d(int z, int z1, ll z2){
if((z == x2 and z1 == 1) or (z == y2 and z1 == 2)) return;
z2 += (m[{z,a[z1][z]}]);
c[a[z1][z]] = max(z2,c[a[z1][z]]);
d(a[z1][z], z1, z2);
}
void f(int z, ll z2){
vis[z] = 1;
for(auto i : v[z]){
if(vis[i.ff] == 0){
if(c[i.ff] >= (z2 + i.ss)){
f(i.ff, z2 + i.ff);
}
}
}
}
int max_score(int n, int x, int y, ll k, vector<int> u, vector<int> u1, vector<int> t){
x2 = x, y2 = y;
for(int i = 0; i <= n; i++) {
v[i].clear();
c[i] = 0;
vis[i] = 0;
for(int j = 0; j <= 3; j++){
a[j][i] = b[j][i] = 0;
}
}
for(int i = 0; i < sz(u); i++){
m[{u[i],u1[i]}] = t[i];
m[{u1[i],u[i]}] = t[i];
v[u[i]].push_back({u1[i], t[i]});
v[u1[i]].push_back({u[i], t[i]});
}
vector <int> v1, v2;
for(auto i : v[x]){
v1.push_back(i.ff);
}
for(auto i : v[y]){
v2.push_back(i.ff);
}
dfs(x, 1);
dfs(y, 2);
while(k > 0){
ll mn = 1e15;
for(auto i : v1){
d1[i] = df(i, 1);
mn = min(d1[i],mn);
}
for(auto i : v1){
d2[i] = df(i, 2);
mn = min(d2[i],mn);
}
int ind = 0, tr = 1;
for(auto i : v1){
if(d1[i] == mn){
ind = i;
break;
}
}
for(auto i : v2){
if(d2[i] == mn){
ind = i;
tr = 2;
break;
}
}
if(mn <= k){
k -= mn;
d(ind, tr, 0);
}
}
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
vis[j] = 0;
}
f(i,0);
ans += (vis[x] + vis[y]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1106 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
71452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1106 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1106 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1106 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1106 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1106 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |