# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
882854 |
2023-12-03T22:05:13 Z |
nikd |
Dreaming (IOI13_dreaming) |
C++17 |
|
41 ms |
14420 KB |
#include <bits/stdc++.h>
#include "dreaming.h"
#define MAXN 100001
using namespace std;
int f;
int max_dis;
int par[MAXN];
int cont=0;
vector<int> mintree;
bool vis[MAXN];
vector<pair<int, int>> adj[MAXN];
int dist[MAXN]={};
void dfs1(int v, int p){
/*vis[v]=true;
for(auto u: adj[v]){
if(u.first!=p){
dist[u.first]=dist[v]+u.second;
if(dist[u.first]>max_dis){
max_dis=dist[u.first];
f=u.first;
}
dfs1(u.first, v);
}
}*/
vis[v] = 1;
if(dist[v] > max_dis)
{
f = v;
max_dis = dist[v];
}
// applying the standard dfs
for( auto u: adj[v] )
{
if(u.first!=p)
{
dist[u.first]=dist[v]+u.second;
dfs1(u.first, v) ;
}
}
}
void dfs2(int v, int p){
/*vis[v]=true;
for(auto u: adj[v]){
if(u.first!=p){
dist[u.first]=dist[v]+u.second;
if(dist[u.first]>max_dis){
max_dis=dist[u.first];
f=u.first;
}
dfs1(u.first, v);
}
}*/
if(dist[v] > max_dis)
{
f = v;
max_dis = dist[v];
}
// applying the standard dfs
for( auto u: adj[v] )
{
if(u.first!=p)
{
dist[u.first]=dist[v]+u.second;
par[u.first]=v;
dfs2(u.first, v) ;
}
}
}
/*void dfs2(int v, int p){
par[v]=p;
for(auto u: adj[v]){
if(u.first!=p){
dist[u.first]=dist[v]+u.second;
if(dist[u.first]>max_dis){
max_dis=dist[u.first];
f=u.first;
}
dfs2(u.first, v);
}
}
}*/
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
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]});
}
for(int i = 0; i<N; i++) vis[i]=false;
for(int i = 0; i<N; i++){
if(!vis[i]){
mintree.push_back(INT_MAX);
max_dis=INT_MIN;
f=-1;
dist[i]=0;
dfs1(i, i);
int a = f;
dist[a]=0;
max_dis=INT_MIN;
f =-1;
dfs2(a, a);
int b = f;
int d= max_dis/2;
int last=-1;
while(dist[b]>d){
last=b;
b=par[b];
}
if(last==-1){
mintree[cont]=dist[b];
}
else{
mintree[cont]=min(dist[last], max_dis-dist[b]);
}
cont++;
}
}
sort(mintree.begin(), mintree.end());
int sol;
int n = cont;
if(n==2){
sol = mintree[0]+mintree[1]+L;
}
else if(n==1) sol =mintree[0];
else{
sol=max(mintree[n-1]+mintree[n-2]+L, mintree[n-2]+mintree[n-3]+2*L);
}
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
7388 KB |
Output is correct |
2 |
Correct |
13 ms |
7504 KB |
Output is correct |
3 |
Correct |
13 ms |
7392 KB |
Output is correct |
4 |
Correct |
14 ms |
7388 KB |
Output is correct |
5 |
Correct |
13 ms |
7384 KB |
Output is correct |
6 |
Correct |
14 ms |
7904 KB |
Output is correct |
7 |
Correct |
15 ms |
7644 KB |
Output is correct |
8 |
Correct |
13 ms |
7392 KB |
Output is correct |
9 |
Correct |
13 ms |
7380 KB |
Output is correct |
10 |
Correct |
14 ms |
7516 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
4 ms |
5080 KB |
Output is correct |
13 |
Correct |
3 ms |
5080 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5080 KB |
Output is correct |
16 |
Correct |
4 ms |
5080 KB |
Output is correct |
17 |
Correct |
3 ms |
5080 KB |
Output is correct |
18 |
Correct |
3 ms |
5228 KB |
Output is correct |
19 |
Correct |
3 ms |
5080 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4544 KB |
Output is correct |
23 |
Correct |
3 ms |
5080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
14420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |