#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define debug(args...) //fprintf(stderr,args)
const int MAXN=112345,INF=1123456789;
vector<int> grafo[MAXN],peso[MAXN];
vector<int> rs;
int maxdist,id,dist[MAXN][2],marc[MAXN][2],rmin,pai[MAXN],pspai[MAXN];
int md;
void dfs1(int v)
{
debug("passando por %d\n",v);
marc[v][0]=1;
if(dist[v][0]>maxdist)
{
maxdist=dist[v][0];
id=v;
}
for(int i=0;i<grafo[v].size();i++)
{
int viz=grafo[v][i],p=peso[v][i];
if(marc[viz][0]==1)continue;
dist[viz][0]=dist[v][0]+p;
dfs1(viz);
}
}
void dfs2(int v)
{
marc[v][1]=1;
if(dist[v][1]>maxdist)
{
maxdist=dist[v][1];
id=v;
}
for(int i=0;i<grafo[v].size();i++)
{
int viz=grafo[v][i],p=peso[v][i];
if(marc[viz][1]==1)continue;
pai[viz]=v;
pspai[viz]=p;
dist[viz][1]=dist[v][1]+p;
dfs2(viz);
}
}
int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
int n=N,m=M,l=L,a[m],b[m],t[m];
for(int i=0;i<m;i++)
{
a[i]=A[i];b[i]=B[i];t[i]=T[i];
}
for(int i=0;i<m;i++)
{
grafo[a[i]].push_back(b[i]);grafo[b[i]].push_back(a[i]);
peso[a[i]].push_back(t[i]);peso[b[i]].push_back(t[i]);
}
md=0;maxdist=0;id=0;
int resp=0;
for(int i=0;i<n;i++)
{
if(marc[i][0]==0)
{
maxdist=0;
dfs1(i);
maxdist=0;
pai[id]=id;
pspai[id]=0;
dfs2(id);
md=max(md,maxdist);
int dm=maxdist,dm1=maxdist;
maxdist=INF;
debug("mdist=%d\n",dm);
while(pai[id]!=id)
{
debug("mdist=%d\n",maxdist);
int k=max(dm1,dm-dm1);
maxdist=min(maxdist,k);
debug("no %d mdist %d pai do no e %d\n",id,maxdist,pai[id]);
dm1-=pspai[id];
id=pai[id];
}
debug("raio do no %d e %d\n",i,maxdist);
rs.push_back(maxdist);
}
}
sort(rs.begin(),rs.end());
int tm=rs.size();
resp=0;
resp=max(resp,md);
for(int i=0;i<tm;i++)
{
debug("raio[%d]=%d\n",i,rs[i]);
}
if(tm>=2)resp=max(resp,rs[tm-1]+rs[tm-2]+l);
if(tm>=3)resp=max(resp,rs[tm-2]+rs[tm-3]+2*l);
return resp;
}
/*int n,m,l,a[MAXN],b[MAXN],t[MAXN];
int main()
{
scanf("%d %d %d",&n,&m,&l);
for(int i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&t[i]);
printf("%d\n",travelTime(n,m,l,a,b,t));
return 0;
}*/
Compilation message
dreaming.cpp: In function 'void dfs1(int)':
dreaming.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grafo[v].size();i++)
~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int)':
dreaming.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grafo[v].size();i++)
~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
19832 KB |
Output is correct |
2 |
Correct |
116 ms |
19796 KB |
Output is correct |
3 |
Correct |
59 ms |
14968 KB |
Output is correct |
4 |
Correct |
16 ms |
7680 KB |
Output is correct |
5 |
Correct |
13 ms |
6912 KB |
Output is correct |
6 |
Correct |
23 ms |
8704 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
38 ms |
11128 KB |
Output is correct |
9 |
Correct |
54 ms |
13048 KB |
Output is correct |
10 |
Correct |
7 ms |
5808 KB |
Output is correct |
11 |
Correct |
93 ms |
15484 KB |
Output is correct |
12 |
Correct |
117 ms |
17656 KB |
Output is correct |
13 |
Correct |
7 ms |
5760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
19832 KB |
Output is correct |
2 |
Correct |
116 ms |
19796 KB |
Output is correct |
3 |
Correct |
59 ms |
14968 KB |
Output is correct |
4 |
Correct |
16 ms |
7680 KB |
Output is correct |
5 |
Correct |
13 ms |
6912 KB |
Output is correct |
6 |
Correct |
23 ms |
8704 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
38 ms |
11128 KB |
Output is correct |
9 |
Correct |
54 ms |
13048 KB |
Output is correct |
10 |
Correct |
7 ms |
5808 KB |
Output is correct |
11 |
Correct |
93 ms |
15484 KB |
Output is correct |
12 |
Correct |
117 ms |
17656 KB |
Output is correct |
13 |
Correct |
7 ms |
5760 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5632 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
19832 KB |
Output is correct |
2 |
Correct |
116 ms |
19796 KB |
Output is correct |
3 |
Correct |
59 ms |
14968 KB |
Output is correct |
4 |
Correct |
16 ms |
7680 KB |
Output is correct |
5 |
Correct |
13 ms |
6912 KB |
Output is correct |
6 |
Correct |
23 ms |
8704 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
38 ms |
11128 KB |
Output is correct |
9 |
Correct |
54 ms |
13048 KB |
Output is correct |
10 |
Correct |
7 ms |
5808 KB |
Output is correct |
11 |
Correct |
93 ms |
15484 KB |
Output is correct |
12 |
Correct |
117 ms |
17656 KB |
Output is correct |
13 |
Correct |
7 ms |
5760 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5632 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
12792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
19832 KB |
Output is correct |
2 |
Correct |
116 ms |
19796 KB |
Output is correct |
3 |
Correct |
59 ms |
14968 KB |
Output is correct |
4 |
Correct |
16 ms |
7680 KB |
Output is correct |
5 |
Correct |
13 ms |
6912 KB |
Output is correct |
6 |
Correct |
23 ms |
8704 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
38 ms |
11128 KB |
Output is correct |
9 |
Correct |
54 ms |
13048 KB |
Output is correct |
10 |
Correct |
7 ms |
5808 KB |
Output is correct |
11 |
Correct |
93 ms |
15484 KB |
Output is correct |
12 |
Correct |
117 ms |
17656 KB |
Output is correct |
13 |
Correct |
7 ms |
5760 KB |
Output is correct |
14 |
Correct |
7 ms |
5760 KB |
Output is correct |
15 |
Correct |
7 ms |
5888 KB |
Output is correct |
16 |
Correct |
7 ms |
5888 KB |
Output is correct |
17 |
Incorrect |
7 ms |
5760 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
19832 KB |
Output is correct |
2 |
Correct |
116 ms |
19796 KB |
Output is correct |
3 |
Correct |
59 ms |
14968 KB |
Output is correct |
4 |
Correct |
16 ms |
7680 KB |
Output is correct |
5 |
Correct |
13 ms |
6912 KB |
Output is correct |
6 |
Correct |
23 ms |
8704 KB |
Output is correct |
7 |
Correct |
6 ms |
5632 KB |
Output is correct |
8 |
Correct |
38 ms |
11128 KB |
Output is correct |
9 |
Correct |
54 ms |
13048 KB |
Output is correct |
10 |
Correct |
7 ms |
5808 KB |
Output is correct |
11 |
Correct |
93 ms |
15484 KB |
Output is correct |
12 |
Correct |
117 ms |
17656 KB |
Output is correct |
13 |
Correct |
7 ms |
5760 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5632 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |