# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105206 |
2019-04-11T00:48:45 Z |
ly20 |
Dreaming (IOI13_dreaming) |
C++14 |
|
127 ms |
18888 KB |
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int MAXN=112345;
vector<int> grafo[MAXN],peso[MAXN];
vector<int> rs;
int maxdist,id,dist[MAXN][3],marc[MAXN][3],rmin;
int md;
void dfs1(int 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;
dist[viz][1]=dist[v][2]+p;
dfs2(viz);
}
}
void dfs3(int v)
{
marc[v][2]=1;
if(dist[v][2]>=rmin)maxdist=min(maxdist,dist[v][2]);
for(int i=0;i<grafo[v].size();i++)
{
int viz=grafo[v][i],p=peso[v][i];
if(marc[viz][2]==1)continue;
dist[viz][2]=dist[v][2]+p;
dfs3(viz);
}
}
int travelTime(int n,int m,int l,int a[],int b[],int t[])
{
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]);
}
int nmc=n-m;
md=0;maxdist=0;id=0;
int resp=0;
for(int i=0;i<nmc;i++)
{
if(marc[i][0]==0)
{
maxdist=0;
dfs1(i);
maxdist=0;
dfs2(id);
md=max(md,maxdist);
rmin=(maxdist+1)/2;
maxdist=0;
dfs3(id);
rs.push_back(maxdist);
}
}
sort(rs.begin(),rs.end());
int tm=rs.size();
resp=0;
resp=max(resp,md);
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;
}
Compilation message
dreaming.cpp: In function 'void dfs1(int)':
dreaming.cpp:17: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:33: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 dfs3(int)':
dreaming.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grafo[v].size();i++)
~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
18888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
18888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
18888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
12424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
18888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
18888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |