# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838604 | nnin | Dreaming (IOI13_dreaming) | C++14 | 1076 ms | 15744 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>
#define f first
#define s second
using namespace std;
vector<pair<int, int>> adj[100005];
vector<int> group[100005];
int maxdis[100005];
bool vis[100005];
int dsu[100005];
int par(int x) {
if(dsu[x]==x) return x;
return dsu[x] = par(dsu[x]);
}
void dfs(int cur, int prev, int dis) {
maxdis[cur] = max(maxdis[cur], dis);
for(auto next:adj[cur]) {
if(prev==next.f) continue;
dfs(next.f, cur, dis+next.s);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<N;i++) dsu[i] = i;
for(int i=0;i<M;i++) {
adj[A[i]].push_back({B[i], T[i]});
adj[B[i]].push_back({A[i], T[i]});
dsu[par(A[i])] = par(B[i]);
}
for(int i=0;i<N;i++) group[par(i)].push_back(i);
int mx = INT_MIN, mx2 = INT_MIN;
for(int i=0;i<N;i++) {
if(group[i].empty()) continue;
for(int j=0;j<group[i].size();j++) {
int st = -1;
int curmx = -1;
for(int k=0;k<group[i].size();k++) {
if(!vis[group[i][k]] && maxdis[group[i][k]]>curmx) {
st = group[i][k];
curmx = maxdis[group[i][k]];
}
}
if(st==-1) break;
dfs(st, -1, 0);
vis[st] = 1;
}
int mngroup = INT_MAX;
for(int j=0;j<group[i].size();j++) {
mngroup = min(mngroup, maxdis[group[i][j]]);
}
if(mngroup>=mx) {
mx2 = mx;
mx = mngroup;
} else if(mngroup>mx2) {
mx2 = mngroup;
}
}
if(mx2==INT_MIN) return mx;
return mx+mx2+L;
}
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... |