# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
962113 | n3rm1n | Dreaming (IOI13_dreaming) | C++17 | 1056 ms | 15344 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<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const long long MAXN = 1e5 + 10;
vector < pair < long long, long long > > g[MAXN];
long long mark[MAXN];
long long used[MAXN];
void dfs0(long long beg)
{
mark[beg] = 1;
used[beg] = 1;
long long nb;
for (long long i = 0; i < g[beg].size(); ++ i)
{
nb = g[beg][i].first;
if(!used[nb])
dfs0(nb);
}
}
long long maxdist = 0;
long long dfs(long long beg)
{
used[beg] = 1;
long long nb, distt;
long long maxx = 0;
for (long long i = 0; i < g[beg].size(); ++ i)
{
nb = g[beg][i].first;
distt = g[beg][i].second;
if(!used[nb])maxx = max(maxx, dfs(nb)+distt);
}
return maxx;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
for (long long i = 0; i < M; ++ i)
{
g[A[i]].push_back(make_pair(B[i], T[i]));
g[B[i]].push_back(make_pair(A[i], T[i]));
}
long long n = N;
dfs0(0);
long long marked1 = 0, marked0 = 0;
long long mindist1 = 1e17, mindist2 = 1e17;
long long currmax;
long long index1 = 0, index2 = 0;
for (long long i = 0; i < n; ++ i)
{
if(mark[i])
{
memset(used, 0 ,sizeof(used));
currmax = dfs(i);
if(currmax < mindist1)
{
mindist1 = currmax;
index1 = i;
}
}
else
{
memset(used, 0 ,sizeof(used));
currmax = dfs(i);
if(currmax < mindist2)
{
mindist2 = currmax;
index2 = i;
}
}
}
g[index1].push_back(make_pair(index2, L));
g[index2].push_back(make_pair(index1, L));
long long ans = 0;
for (long long i = 0; i < n; ++ i)
{
memset(used, 0, sizeof(used));
ans = max(ans, dfs(i));
}
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... |