#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
struct cell
{
int to,cost;
};
int n,m,l,g;
int a1[100005],a2[100005],a3[100005],ma[100005],sma[100005],dul[100005],in[100005],costin[100005],used[100005],otg[100005];
vector<cell>v[100005];
void find_ma(int beg)
{
used[beg]=1;
int w;
for(int i=0;i<(int)(v[beg].size());i++)
{
w=v[beg][i].to;
if(!used[w])
{
find_ma(w);
if(ma[beg]<ma[w]+v[beg][i].cost)
{
sma[beg]=ma[beg];
ma[beg]=ma[w]+v[beg][i].cost;
costin[beg]=v[beg][i].cost;
in[beg]=w;
}
else if(sma[beg]<ma[w]+v[beg][i].cost)
{
sma[beg]=ma[w]+v[beg][i].cost;
}
}
}
}
void find_mid(int beg,int izm,int par)
{
if(izm>=ma[beg])
{
otg[beg]=min(izm,ma[par]);
return;
}
find_mid(in[beg],max(izm,sma[beg])+costin[beg],beg);
}
void fil(int beg)
{
used[beg]=1;
int w;
for(int i=0;i<(int)(v[beg].size());i++)
{
w=v[beg][i].to;
if(!used[w])
{
fil(w);
}
}
}
int travelTime(int n,int m,int l,int a1[],int a2[],int a3[])
//void read()
{
//cin>>n>>m>>l;
cell h;
for(int i=1;i<=m;i++)
{
//cin>>a1[i]>>a2[i]>>a3[i];
h.to=a1[i];
h.cost=a3[i];
v[a2[i]].push_back(h);
h.to=a2[i];
v[a1[i]].push_back(h);
}
for(int i=1;i<=n;i++)
{
if(!used[i])
{
find_ma(i);
}
}
int aa=0;
for(int i=1;i<=n;i++)
{
dul[i]=ma[i]+sma[i];
if(aa<dul[i])
{
aa=dul[i];
g=i;
}
}
memset(used,0,sizeof(used));
for(int i=1;i<=n;i++)
{
if(!used[i])
{
find_mid(i,0,0);
fil(i);
}
}
sort(otg+1,otg+n+1);
if(m!=n-2)
{
aa=max(aa,2*l+otg[n-1]+otg[n-2]);
}
aa=max(aa,l+otg[n-1]+otg[n]);
//cout<<aa<<endl;
return aa;
}
/*int main()
{
speed();
read();
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
13904 KB |
Output is correct |
2 |
Correct |
37 ms |
14416 KB |
Output is correct |
3 |
Correct |
21 ms |
9812 KB |
Output is correct |
4 |
Correct |
5 ms |
5724 KB |
Output is correct |
5 |
Correct |
4 ms |
5072 KB |
Output is correct |
6 |
Incorrect |
11 ms |
6492 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
13904 KB |
Output is correct |
2 |
Correct |
37 ms |
14416 KB |
Output is correct |
3 |
Correct |
21 ms |
9812 KB |
Output is correct |
4 |
Correct |
5 ms |
5724 KB |
Output is correct |
5 |
Correct |
4 ms |
5072 KB |
Output is correct |
6 |
Incorrect |
11 ms |
6492 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8284 KB |
Output is correct |
2 |
Correct |
15 ms |
8540 KB |
Output is correct |
3 |
Correct |
15 ms |
8488 KB |
Output is correct |
4 |
Correct |
15 ms |
8284 KB |
Output is correct |
5 |
Correct |
15 ms |
8280 KB |
Output is correct |
6 |
Correct |
15 ms |
8804 KB |
Output is correct |
7 |
Correct |
15 ms |
8536 KB |
Output is correct |
8 |
Correct |
19 ms |
8284 KB |
Output is correct |
9 |
Correct |
14 ms |
8284 KB |
Output is correct |
10 |
Correct |
18 ms |
8848 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
4 ms |
6236 KB |
Output is correct |
13 |
Correct |
4 ms |
6248 KB |
Output is correct |
14 |
Correct |
3 ms |
6336 KB |
Output is correct |
15 |
Correct |
3 ms |
6236 KB |
Output is correct |
16 |
Correct |
4 ms |
5980 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
4 ms |
6492 KB |
Output is correct |
19 |
Correct |
4 ms |
5980 KB |
Output is correct |
20 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
13904 KB |
Output is correct |
2 |
Correct |
37 ms |
14416 KB |
Output is correct |
3 |
Correct |
21 ms |
9812 KB |
Output is correct |
4 |
Correct |
5 ms |
5724 KB |
Output is correct |
5 |
Correct |
4 ms |
5072 KB |
Output is correct |
6 |
Incorrect |
11 ms |
6492 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |