#include<bits/stdc++.h>
#include "dreaming.h"
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vdb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<int> si;
typedef set<long long> sl;
typedef set<double> sdb;
typedef set<string> ss;
typedef set<char> sc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ftb(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define ft(i, a, b) for (int i = a, _b = b; i < _b; ++i)
#define fgb(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define fg(i, a, b) for (int i = a, _b = b; i > _b; --i)
#define endl "\n"
const int N = 20;
vector<pii> adj[N + 1];
int color[N + 1];
ll up[N + 1];
ll down[N + 1];
vl ans(N + 1, 1e16);
void dfsDown(int node) {
for (pii it : adj[node]) {
if (color[it.first] == 0) {
color[it.first] = color[node];
dfsDown(it.first);
down[node] = max(down[node], down[it.first] + it.second);
}
}
}
void dfsUp(int node, int parent) {
ll mx1 = -1, mx2 = -1;
for (pii it : adj[node]) {
if (it.first != parent) {
if (down[it.first] + it.second > mx1) {
mx2 = mx1;
mx1 = down[it.first] + it.second;
}
else {
mx2 = max(mx2, down[it.first] + it.second);
}
}
}
for (pii it : adj[node]) {
if (it.first != parent) {
up[it.first] = up[node] + it.second;
if (down[it.first] + it.second != mx1) {
up[it.first] = max(up[it.first], mx1 + it.second);
}
else {
up[it.first] = max(up[it.first], mx2 + it.second);
}
dfsUp(it.first, node);
}
}
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
ft(i, 0, m) {
adj[a[i]].push_back({ b[i],t[i] });
adj[b[i]].push_back({ a[i],t[i] });
}
int num = 1;
ft(i, 0, n) {
if (color[i] == 0) {
color[i] = num++;
dfsDown(i);
dfsUp(i, 0);
}
}
ft(i, 0, n) {
ans[color[i]] = min(ans[color[i]], max(down[i], up[i]));
}
vl temp;
ft(i, 1, num) {
temp.push_back(ans[i]);
}
sort(temp.rbegin(), temp.rend());
if (temp.size() == 1) {
return temp[0];
}
if (temp.size() == 2) {
return temp[0] + temp[1] + l;
}
return max(temp[0] + temp[1] + l, temp[1] + temp[2] + 2 * l);
}
// int main() {
// int n, m, l;
// cin >> n >> m >> l;
// int a[m], b[m], t[m];
// ft(i, 0, m) {
// cin >> a[i];
// }
// ft(i, 0, m) {
// cin >> b[i];
// }
// ft(i, 0, m) {
// cin >> t[i];
// }
// int kq = travelTime(n, m, l, a, b, t);
// cout << kq;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
2652 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
2652 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
1220 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
2652 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |