Submission #881838

#TimeUsernameProblemLanguageResultExecution timeMemory
881838_KuroNeko_Dreaming (IOI13_dreaming)C++17
100 / 100
46 ms19028 KiB
#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 = 1e5; 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); } } ll kq = 0; ft(i, 0, n) { ans[color[i]] = min(ans[color[i]], max(down[i], up[i])); kq = max(kq, 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 max(kq, temp[0]); } if (temp.size() == 2) { return max(kq, temp[0] + temp[1] + l); } return max(kq, 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...