# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
846566 |
2023-09-07T23:17:30 Z |
midi |
Dreaming (IOI13_dreaming) |
C++14 |
|
344 ms |
32232 KB |
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vc vector
typedef vc<ll> vcll;
#define pr pair
typedef pr<ll, ll> prll;
#define f0r(i,a,n) for (i=a; i<n; i++)
#define f1r(i,a,n) for (i=a; i<=n; i++)
#define r0f(i,n,a) for (i=n; i>a; i--)
#define r1f(i,n,a) for (i=n; i>=a; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define in(s, x) ((s).find((x)) != (s).end())
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
inline void maxa(ll &a, ll b) { if (a<b) a=b; }
inline void mina(ll &a, ll b) { if (a>b) a=b; }
#define INF (LLONG_MAX>>1ll)
#define mxN 100'010ll
ll n, m, l;
int *uar, *var, *war;
vc<vc<prll>> gr(mxN); // fi is w, se is v
vcll ar;
inline void build_gr()
{
ll i;
f0r(i,0,m)
{
ll u, v, w;
u=uar[i];
v=var[i];
w=war[i];
gr[u].pb({w, v});
gr[v].pb({w, u});
}
}
vc<bool> seen(mxN, 0);
map<prll, ll> from_to; // the "to" gives the value
inline void init_umap()
{
ll u;
f0r(u,0,n)
{
from_to[mp(-1,u)]=-1;
for (prll edge : gr[u])
{
ll v = edge.se;
from_to[mp(u,v)]=-1;
from_to[mp(v,u)]=-1;
}
}
}
vcll comp; // comp for component
void dfs(ll u)
{
if (seen[u]) return;
// printf("real, u: %lli\n", u);
seen[u]=1;
comp.pb(u);
for (prll edge : gr[u])
{
ll v=edge.se;
dfs(v);
}
}
ll calc_from_to(ll p, ll u)
{
ll &t = from_to[mp(p,u)];
// if (t!=-1) printf("p: %lli, u: %lli, t: %lli\n", p, u, t);
if (t!=-1) return t;
ll m=0; // max
for (prll edge : gr[u])
{
ll v=edge.se;
if (v==p) continue;
ll w=edge.fi;
maxa(m, calc_from_to(u,v)+w);
}
// printf("res: %lli\n", m);
return t=m;
}
inline ll minmaxdist(ll u)
{
comp.clear();
dfs(u);
// printf("comp.size: %lli\n", (ll)comp.size());
ll m=INF; // min
for (ll u : comp)
{
mina(m, calc_from_to(-1, u));
// printf("min: %lli\n", m);
}
// printf("true\n");
return m;
}
inline void build_ar()
{
init_umap();
ll u;
f0r(u,0,n)
{
if (seen[u]) continue;
ar.pb(minmaxdist(u));
// printf("ar.back(): %lli\n", ar.back());
}
}
inline ll value()
{
ll z=ar.size();
// printf("z: %lli\n", z);
if (z==1) return ar[0];
if (z==2) return ar[0]+ar[1]+l;
return max(ar[0]+ar[1]+l, ar[1]+ar[2]+(2*l));
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
n=N;
m=M;
l=L;
uar=A;
var=B;
war=T;
build_gr();
build_ar();
sort(allrev(ar));
return value();
}
/*
int main()
{
freopen("dreaming.in", "r", stdin);
int N, M, L, *A, *B, *T;
A=new int[mxN];
B=new int[mxN];
T=new int[mxN];
cin >> N >> M >> L;
ll i;
f0r(i,0,M) cin >> A[i] >> B[i] >> T[i];
int v = travelTime(N, M, L, A, B, T);
printf("ans: %i\n", v);
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
344 ms |
32232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
344 ms |
32232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
15312 KB |
Output is correct |
2 |
Correct |
97 ms |
15516 KB |
Output is correct |
3 |
Correct |
96 ms |
15316 KB |
Output is correct |
4 |
Correct |
95 ms |
15520 KB |
Output is correct |
5 |
Correct |
96 ms |
15316 KB |
Output is correct |
6 |
Correct |
107 ms |
16584 KB |
Output is correct |
7 |
Correct |
110 ms |
16076 KB |
Output is correct |
8 |
Correct |
96 ms |
15136 KB |
Output is correct |
9 |
Correct |
90 ms |
15056 KB |
Output is correct |
10 |
Correct |
91 ms |
16076 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
23 ms |
10196 KB |
Output is correct |
13 |
Correct |
25 ms |
10192 KB |
Output is correct |
14 |
Correct |
23 ms |
10448 KB |
Output is correct |
15 |
Correct |
24 ms |
10460 KB |
Output is correct |
16 |
Correct |
22 ms |
10200 KB |
Output is correct |
17 |
Correct |
26 ms |
10200 KB |
Output is correct |
18 |
Correct |
24 ms |
10196 KB |
Output is correct |
19 |
Correct |
24 ms |
10196 KB |
Output is correct |
20 |
Correct |
2 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2904 KB |
Output is correct |
23 |
Correct |
23 ms |
10204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
344 ms |
32232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |