# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
415748 | Emin2004 | Dreaming (IOI13_dreaming) | C++14 | 77 ms | 15072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
const int N = 100005;
int used[N];
int dis[N][2];
vector <pii> v[N];
vector <int> vis;
void DFS(int node, int r){
used[node] = 1;
vis.pb(node);
for(pii i : v[node]){
if(!used[i.F]){
used[i.F] = 1;
dis[i.F][r] = dis[node][r] + i.S;
DFS(i.F, r);
}
}
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
// return n;
if(n == 1) return 0;
for(int i = 0; i < m; i++){
v[a[i]].pb({b[i], t[i]});
v[b[i]].pb({a[i], t[i]});
}
vector<int> results;
for(int i = 0; i < n; i++){
if(!used[i]) {
DFS(i,0);
int mx = 0, dd;
for(int j : vis){
used[j] = 0;
if(dis[j][0] > mx) {
mx = dis[j][0];
dd = j;
}
dis[j][0] = 0;
}
vis.clear();
DFS(dd, 0);
mx = 0;
for(int j : vis){
used[j] = 0;
if(dis[j][0] > mx) {
mx = dis[j][0];
dd = j;
}
}
vis.clear();
DFS(dd, 1);
for(int j : vis){
mx = min(mx, max(dis[j][0], dis[j][1]));
dis[j][0] = 0;
dis[j][1] = 0;
}
vis.clear();
results.pb(mx);
// return mx;
}
}
sort(results.begin(), results.end());
int sz = results.size();
int ans = results[sz - 1];
if(sz >= 2) ans += results[sz - 2] + l;
if(sz >= 3) ans = max(ans, results[sz - 2] + results[sz - 3] + l + l);
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |