#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 1e5 + 69;
vector<pair<int, int>> graph[N];
ll dp[N];
bool visited[N];
void go(int u, int p){
dp[u] = 0;
visited[u] = true;
for(auto v: graph[u]) if (v.first != p){
go(v.first, u);
maximize(dp[u], dp[v.first] + v.second);
}
}
void dfs(int u, int p, ll &ans){
minimize(ans, dp[u]);
pair<ll, ll> ma = {0, 0};
for(auto v: graph[u]) {
ll val = dp[v.first] + v.second;
if (val > ma.first){
ma.second = ma.first;
ma.first = val;
}
else maximize(ma.second, val);
}
for(auto v: graph[u]) if (v.first != p){
ll x = dp[u], y = dp[v.first];
if (dp[v.first] + v.second == ma.first) dp[u] = ma.second;
else dp[u] = ma.first;
maximize(dp[v.first], dp[u] + v.second);
dfs(v.first, u, ans);
dp[u] = x; dp[v.first] = y;
}
}
int travelTime(int n,int m,int l,int A[],int B[],int T[]){
for(int i = 0; i<n; ++i){
graph[i].clear(); visited[i] = 0; dp[i] = 0;
}
for(int i = 0; i<m; ++i){
int u = A[i], v = B[i], w = T[i];
graph[u].push_back({v, w});
graph[v].push_back({u, w});
}
vector<ll> lmao;
for(int i = 0; i<n; ++i) if (!visited[i]){
go(i, i);
ll cur = 1e18;
dfs(i, i, cur);
lmao.push_back(cur);
}
sort(ALL(lmao));
ll ans = lmao.back();
if (lmao.size() >= 2) maximize(ans, lmao[lmao.size() - 2] + lmao.back() + l);
if (lmao.size() >= 3) maximize(ans, lmao[lmao.size() - 3] + lmao[lmao.size() - 2] + 2 * l);
return ans;
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int A[] = {0,8,2,5,5,1,1,10}, B[] = {8,2,7,11,1,3,9,6}, C[] = {4,2,4,3,7,1,5,3};
// cout << travelTime(12, 8, 2, A,B,C) << "\n";
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
13552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
13552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
7392 KB |
Output is correct |
2 |
Correct |
13 ms |
7388 KB |
Output is correct |
3 |
Correct |
13 ms |
7388 KB |
Output is correct |
4 |
Correct |
22 ms |
7388 KB |
Output is correct |
5 |
Correct |
13 ms |
7388 KB |
Output is correct |
6 |
Correct |
14 ms |
8156 KB |
Output is correct |
7 |
Correct |
14 ms |
7392 KB |
Output is correct |
8 |
Correct |
12 ms |
7136 KB |
Output is correct |
9 |
Correct |
13 ms |
7240 KB |
Output is correct |
10 |
Correct |
14 ms |
7640 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
3 ms |
5844 KB |
Output is correct |
13 |
Correct |
4 ms |
5676 KB |
Output is correct |
14 |
Correct |
4 ms |
5840 KB |
Output is correct |
15 |
Correct |
4 ms |
5844 KB |
Output is correct |
16 |
Correct |
3 ms |
5684 KB |
Output is correct |
17 |
Correct |
4 ms |
5844 KB |
Output is correct |
18 |
Correct |
4 ms |
5844 KB |
Output is correct |
19 |
Correct |
4 ms |
5844 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
4 ms |
5844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
13552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |