# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
30169 |
2017-07-22T20:37:33 Z |
inqr |
Dreaming (IOI13_dreaming) |
C++14 |
|
1000 ms |
15336 KB |
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define all(x) x.begin() , x.end()
using namespace std;
int n,m,l,ans=-1;
vector < pair < int , int > > ed[150005];
bool in_for[150005];
vector < int > radius;
int maxw,maxwv,dia1,dia2,mincw,mincwv;
vector < int > d1,d2;
void dfs(int vn,int vb,int wn,vector<int>&d){
//printf(" 1:vn=%d vb=%d wn=%d\n",vn,vb,wn);
if(wn>maxw){
maxw=wn;
maxwv=vn;
}
in_for[vn]=1;
d[vn]=wn;
if(d1[vn]!=1e9&&d2[vn]!=1e9&&max(d1[vn],d2[vn])<mincw){
mincw=max(d1[vn],d2[vn]);
mincwv=vn;
}
for(int i=0;i<ed[vn].size();i++)
if(ed[vn][i].st!=vb)
dfs(ed[vn][i].st,vn,wn+ed[vn][i].nd,d);
}
void for_fn(int rt){
d1=d2=vector < int >(150005,1e9);
maxw=maxwv=dia1=dia2=mincwv=-1;mincw=1e9;
//printf("1:rt=%d\n",rt);
if(ed[rt].size()==0){
in_for[rt]=1;
radius.pb(0);
return;
}
dfs(rt,-1,0,d1);
dia1=maxwv;maxw=-1;
ans=max(ans,maxw);
//printf("2:dia1=%d\n",dia1);
dfs(dia1,-1,0,d1);
dia2=maxwv;maxw=-1;
//printf("2:dia2=%d\n",dia2);
dfs(dia2,-1,0,d2);
//printf("rt=%d mincw=%d mincwv=%d\n",rt,mincw,mincwv);
radius.pb(mincw);
}
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++){
ed[A[i]].pb(mp(B[i],T[i]));
ed[B[i]].pb(mp(A[i],T[i]));
}
for(int i=0;i<N;i++){
if(!in_for[i])for_fn(i);
}
sort(all(radius));int rs=radius.size();
if(rs==1)return ans;
if(rs==2){
umax(ans,radius[0]+radius[1]+l);return ans;
}
for(int i=0;i<rs-1;i++){
umax(ans,radius[i]+radius[rs-1]+l);
}
umax(ans,radius[rs-2]+radius[rs-3]+2*l);
return ans;
}
Compilation message
dreaming.cpp: In function 'void dfs(int, int, int, std::vector<int>&)':
dreaming.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ed[vn].size();i++)
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
15336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
15336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
15336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1071 ms |
8248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
15336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
15336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |