# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
947377 |
2024-03-16T04:33:59 Z |
adkjt |
Dreaming (IOI13_dreaming) |
C++14 |
|
33 ms |
17288 KB |
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define f first
#define s second
#define pii pair<int,int>
vector<pii> g[111111];
int dis[111111],vis[111111],cendis[111111];
vector<int> diameter[111111];
int mxi=0,mxd=0,cntg=0,st,en,mxg1=-1,mxg2=-1,mxg3=-1,mx0=-1;
void dfs(int now,int p)
{
vis[now]=1;
if(dis[now]>mxd)
mxd=dis[now],mxi=now;
//vis[now]=1;
for(auto x:g[now])
{
if(x.f==p) continue;
dis[x.f]=dis[now]+x.s;
dfs(x.f,now);
}
}
bool diamake(int now,int prev,int en)
{
diameter[cntg].push_back(now);
if(now==en) return 1;
for(auto x:g[now])
{
if(x.f==prev) continue;
if(diamake(x.f,now,en)) return 1;
}
diameter[cntg].pop_back();
return 0;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<M;i++)
{
g[A[i]].push_back({B[i],T[i]});
g[B[i]].push_back({A[i],T[i]});
}
//for(int i=1;i<=N;i++) dis[i]=INT_MAX;
for(int i=0;i<N;i++)
{
if(vis[i]) continue;
cntg++;
//vis[i]=1;
mxi=-1,mxd=-1;
dis[i]=0;
dfs(i,-1);
st=mxi;
mxi=-1,mxd=-1;
dis[st]=0;
dfs(st,-1);
en=mxi;
diamake(st,-1,en);
mx0=max(mx0,mxd);
//disdia[cntg]=mxd;
cendis[cntg]=INT_MAX;
//cout<<mxd<<'\n';
for(auto x:diameter[cntg]) cendis[cntg]=min(cendis[cntg],max(dis[x],mxd-dis[x]));
//cout<<cendis[cntg]<<'\n';
if(mxg1==-1||cendis[cntg]>mxg1) mxg3=mxg2,mxg2=mxg1,mxg1=cendis[cntg];
else if(mxg2==-1||cendis[cntg]>mxg2) mxg3=mxg2,mxg2=cendis[cntg];
else if(mxg3==-1||cendis[cntg]>mxg3) mxg3=cendis[cntg];
//cout<<st<<' '<<en<<'\n';
}
//cout<<mxg1<<' '<<mxg2<<' '<<mxg3<<'\n';
if(mxg3==-1) return mxg1+mxg2+L;
return max({mx0,mxg1+mxg2+L,mxg2+mxg3+2*L});
}
/*int main()
{
int n,m,l,a[111111],b[111111],t[111111];
cin>>n>>m>>l;
for(int i=0;i<m;i++)
cin>>a[i]>>b[i]>>t[i];
cout<<travelTime(n,m,l,a,b,t);
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
17288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
17288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11864 KB |
Output is correct |
2 |
Correct |
16 ms |
11868 KB |
Output is correct |
3 |
Correct |
16 ms |
11868 KB |
Output is correct |
4 |
Correct |
21 ms |
11880 KB |
Output is correct |
5 |
Correct |
18 ms |
11864 KB |
Output is correct |
6 |
Correct |
18 ms |
12124 KB |
Output is correct |
7 |
Correct |
16 ms |
12120 KB |
Output is correct |
8 |
Correct |
15 ms |
11868 KB |
Output is correct |
9 |
Correct |
15 ms |
11892 KB |
Output is correct |
10 |
Correct |
16 ms |
12124 KB |
Output is correct |
11 |
Correct |
2 ms |
7772 KB |
Output is correct |
12 |
Correct |
7 ms |
10884 KB |
Output is correct |
13 |
Correct |
7 ms |
11096 KB |
Output is correct |
14 |
Correct |
7 ms |
10844 KB |
Output is correct |
15 |
Correct |
7 ms |
11100 KB |
Output is correct |
16 |
Correct |
7 ms |
10844 KB |
Output is correct |
17 |
Correct |
7 ms |
10844 KB |
Output is correct |
18 |
Correct |
8 ms |
11100 KB |
Output is correct |
19 |
Correct |
7 ms |
11100 KB |
Output is correct |
20 |
Incorrect |
2 ms |
7772 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
17288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |