#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int n,m,l,ans=0,vis[100001];
vector<iii> al[100001];
vi v;
int dfs(int node,int p)
{
vis[node]=1;
for(int i=0;i<al[node].size();++i)
{
if(!vis[al[node][i].S.F])
{
al[node][i].F=dfs(al[node][i].S.F,node);
al[node][i].F+=al[node][i].S.S;
}
}
sort(all(al[node]));
return(al[node].back().F);
}
void dfs2(int node,int p)
{
sort(all(al[node]));
int to=al[node].back().S.F;
ans=min(ans,al[node].back().F);
if(to==p)
return;
for(int i=0;i<al[to].size();++i)
{
if(al[to][i].S.F==node)
{
al[to][i].F=al[node][al[node].size()-2].F+al[to][i].S.S;
break;
}
}
dfs2(to,node);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
n=N;
m=M;
l=L;
for(int i=0;i<m;++i)
{
al[A[i]].pb(mp(0,mp(B[i],T[i])));
al[B[i]].pb(mp(0,mp(A[i],T[i])));
}
for(int i=0;i<n;++i)
al[i].pb(mp(0,mp(i,i)));
for(int i=0;i<n;++i)
{
if(!vis[i])
{
dfs(i,i);
ans=1000000000;
dfs2(i,i);
v.pb(ans);
}
}
sort(all(v));
ans=v.back();
if(v.size()>1)
ans=v.back()+v[v.size()-2]+l;
if(v.size()>2)
ans=max(ans,2*l+v[v.size()-2]+v[v.size()-3]);
return(ans);
}
Compilation message
dreaming.cpp: In function 'int dfs(int, int)':
dreaming.cpp:24:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[node].size();++i)
~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[to].size();++i)
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
15480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
15480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
15480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
7160 KB |
Output is correct |
2 |
Correct |
36 ms |
7168 KB |
Output is correct |
3 |
Correct |
34 ms |
7172 KB |
Output is correct |
4 |
Correct |
42 ms |
7268 KB |
Output is correct |
5 |
Correct |
35 ms |
7168 KB |
Output is correct |
6 |
Correct |
41 ms |
7672 KB |
Output is correct |
7 |
Correct |
37 ms |
7420 KB |
Output is correct |
8 |
Correct |
37 ms |
7040 KB |
Output is correct |
9 |
Correct |
32 ms |
7040 KB |
Output is correct |
10 |
Correct |
39 ms |
7288 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
19 ms |
6912 KB |
Output is correct |
13 |
Correct |
13 ms |
6912 KB |
Output is correct |
14 |
Correct |
13 ms |
6912 KB |
Output is correct |
15 |
Correct |
13 ms |
6784 KB |
Output is correct |
16 |
Correct |
12 ms |
6784 KB |
Output is correct |
17 |
Correct |
17 ms |
6784 KB |
Output is correct |
18 |
Correct |
13 ms |
6912 KB |
Output is correct |
19 |
Correct |
13 ms |
6784 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
13 ms |
6912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
15480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
15480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |