Submission #468414

#TimeUsernameProblemLanguageResultExecution timeMemory
468414jazzupDreaming (IOI13_dreaming)C++14
77 / 100
119 ms18500 KiB
#include "dreaming.h" #include <queue> #include <vector> #include <utility> #include <algorithm> #include <cmath> using namespace std; int dis1[200010],dis2[200010]; bool visited[200010]; vector<pair<int,int> > v[200010],pb; vector<int> pa,nl,len; queue<int> q; int a[100010],b[100010],c[100010]; bool shd; void dfs(pair<int,int> n){ visited[n.first]=true; nl.push_back(n.first); if(dis2[n.first]==n.second){ double targ=n.second/2.0; double dd=targ; int pu; for(int i=0;i<nl.size();i++){ double diff=abs((double)dis2[nl[i]]-targ); if(diff<=dd){ dd=diff; pu=max(dis2[nl[i]],n.second-dis2[nl[i]]); } } if(!shd){ len.push_back(pu); shd=true; } else if(pu<len.back()){ len.pop_back(); len.push_back(pu); } } for(int i=0;i<v[n.first].size();i++){ if(!visited[v[n.first][i].first]){ dis2[v[n.first][i].first]=dis2[n.first]+v[n.first][i].second; dfs(make_pair(v[n.first][i].first,n.second)); } } nl.pop_back(); } int travelTime(int n, int m, int l, int a[], int b[], int t[]){ for(int i=0;i<n;i++){ dis1[i]=-1; } for(int i=0;i<m;i++){ v[a[i]].push_back(make_pair(b[i],t[i])); v[b[i]].push_back(make_pair(a[i],t[i])); } for(int i=0;i<n;i++){ if(dis1[i]==-1){ dis1[i]=0; q.push(i); visited[i]=true; int mxd=0,nd=i; while(!q.empty()){ int cur=q.front(); if(dis1[cur]>mxd){ mxd=dis1[cur]; nd=cur; } q.pop(); for(int i=0;i<v[cur].size();i++){ if(!visited[v[cur][i].first]){ q.push(v[cur][i].first); dis1[v[cur][i].first]=dis1[cur]+v[cur][i].second; visited[v[cur][i].first]=true; } } } pa.push_back(nd); } } for(int i=0;i<n;i++){ dis1[i]=-1; visited[i]=false; } for(int i=0;i<pa.size();i++){ dis1[pa[i]]=0; q.push(pa[i]); visited[pa[i]]=true; int mxd=0,nd=i; while(!q.empty()){ int cur=q.front(); if(dis1[cur]>mxd){ mxd=dis1[cur]; nd=cur; } q.pop(); for(int i=0;i<v[cur].size();i++){ if(!visited[v[cur][i].first]){ q.push(v[cur][i].first); dis1[v[cur][i].first]=dis1[cur]+v[cur][i].second; visited[v[cur][i].first]=true; } } } pb.push_back(make_pair(nd,mxd)); } for(int i=0;i<n;i++){ dis2[i]=-1; visited[i]=false; } for(int i=0;i<pb.size();i++){ dis2[pb[i].first]=0; shd=false; dfs(pb[i]); } sort(len.begin(),len.end()); int ml=-1; for(int i=0;i<n;i++){ if(dis2[i]>ml){ ml=dis2[i]; } } int yo=n-m; int ans=-1; if(yo>=3){ ans=max(len[yo-1]+len[yo-2]+l,len[yo-3]+len[yo-2]+2*l); } else if(yo==2){ ans=len[yo-1]+len[yo-2]+l; } ans=max(ans,ml); // printf("%lld\n",yo); return ans; }

Compilation message (stderr)

dreaming.cpp: In function 'void dfs(std::pair<int, int>)':
dreaming.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i=0;i<nl.size();i++){
      |               ~^~~~~~~~~~
dreaming.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i=0;i<v[n.first].size();i++){
      |              ~^~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=0;i<v[cur].size();i++){
      |                 ~^~~~~~~~~~~~~~
dreaming.cpp:95:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for(int i=0;i<pa.size();i++){
      |              ~^~~~~~~~~~
dreaming.cpp:109:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |    for(int i=0;i<v[cur].size();i++){
      |                ~^~~~~~~~~~~~~~
dreaming.cpp:125:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |  for(int i=0;i<pb.size();i++){
      |              ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...