Submission #290730

# Submission time Handle Problem Language Result Execution time Memory
290730 2020-09-04T11:37:27 Z AKaan37 Dreaming (IOI13_dreaming) C++17
18 / 100
95 ms 28152 KB
//Bismillahirrahmanirrahim
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 2000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,co[li],vis[li],mx[li],mn;
int cev;
string s;
vector<PII> v[li];
vector<int> vec;
//~ int A[li],B[li],T[li];

inline void dfs(int node,int ata){
	vis[node]=1;
	int mx1=0,mx2=0;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i].fi;
		if(go==ata)continue;
		dfs(go,node);
		co[node]=max(co[node],co[go]+v[node][i].se);
		mx2=max(mx2,co[go]+v[node][i].se);
		if(mx2>mx1)swap(mx1,mx2);
	}
	cev=max(cev,mx1+mx2);
	//~ cout<<node<<endl;
	mx[node]=max(mx[node],co[node]);
}

inline void dfs1(int node,int ata,int der){
	vis[node]=1;
	multiset<int> st;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i].fi;
		if(go==ata)continue;
		st.insert(co[go]+v[node][i].se);
	}
	int der1=der;
	int mx1=0;
	int mx2=0;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i].fi;
		if(go==ata)continue;
		auto it=st.end();
		it--;
		if(*it==co[go]+v[node][i].se){
			if(it!=st.begin()){
				it--;
				der1=max(der1,*it);
			}
		}
		else der1=max(der1,*it);
		mx2=max(mx2,co[go]);
		if(mx2>mx1)swap(mx2,mx1);
		dfs1(go,node,der1+v[node][i].se);
	}
	mx2=max(mx2,der);
	if(mx2>mx1)swap(mx2,mx1);
	mx[node]=max(mx[node],mx2+mx1);
	//~ cev=max(cev,mx[node]);
	mn=min(mn,mx[node]);
}

int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
    for(int i=0;i<m;i++){
		v[A[i]].pb({B[i],T[i]});
		v[B[i]].pb({A[i],T[i]});
	}
    FOR{
		if(vis[i])continue;
		mn=inf;
		dfs(i,-1);
		dfs1(i,-1,0);
		vec.pb(mn);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	//~ for(int i=0;i<(int)vec.size();i++)cout<<vec[i]<<endl;
	for(int i=1;i<(int)vec.size();i++){
		cev=max(cev,vec[0]+vec[i]+l);
	}
	for(int i=2;i<(int)vec.size();i++){
		cev=max(cev,vec[1]+vec[i]+2*l);
	}
	return cev;
}
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 15860 KB Output is correct
2 Correct 37 ms 15864 KB Output is correct
3 Correct 37 ms 15864 KB Output is correct
4 Correct 47 ms 15864 KB Output is correct
5 Correct 37 ms 15864 KB Output is correct
6 Correct 40 ms 16380 KB Output is correct
7 Correct 38 ms 16128 KB Output is correct
8 Correct 36 ms 15872 KB Output is correct
9 Correct 36 ms 15732 KB Output is correct
10 Correct 38 ms 15996 KB Output is correct
11 Correct 9 ms 12032 KB Output is correct
12 Correct 13 ms 13820 KB Output is correct
13 Correct 13 ms 13820 KB Output is correct
14 Correct 13 ms 13820 KB Output is correct
15 Correct 12 ms 13820 KB Output is correct
16 Correct 13 ms 13820 KB Output is correct
17 Correct 13 ms 13564 KB Output is correct
18 Correct 14 ms 13820 KB Output is correct
19 Correct 12 ms 13820 KB Output is correct
20 Correct 8 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
22 Correct 8 ms 12160 KB Output is correct
23 Correct 15 ms 13820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -