Submission #340264

#TimeUsernameProblemLanguageResultExecution timeMemory
340264KerimDreaming (IOI13_dreaming)C++17
100 / 100
151 ms16952 KiB
#include <bits/stdc++.h> #include "dreaming.h" #define MAXN 100009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} vector<PII>adj[MAXN]; int mx,mn=INF,who,d[MAXN][2],vis[MAXN]; void dfs(int nd,int pr,int lvl){ if(umax(mx,lvl))who=nd; tr(it,adj[nd]) if(it->ff!=pr) dfs(it->ff,nd,lvl+it->ss); }vector<int>v; void dfs1(int nd,int pr,int t,int lvl=0){ d[nd][t]=lvl;v.pb(nd); tr(it,adj[nd]) if(it->ff!=pr) dfs1(it->ff,nd,t,lvl+it->ss); } void dfs2(int nd,int pr){ umin(mn,max(d[nd][0],d[nd][1])); vis[nd]=1; tr(it,adj[nd]) if(it->ff!=pr) dfs2(it->ff,nd); } int travelTime(int n,int m,int l,int a[],int b[],int t[]){ if(n==1)return 0;int dia=0; for(int i=0;i<m;i++) adj[a[i]].pb(mp(b[i],t[i])),adj[b[i]].pb(mp(a[i],t[i])); vector<int>v; for(int i=0;i<n;i++) if(!vis[i]){ mx=-1,dfs(i,-1,0);int a=who; mx=-1,dfs(a,-1,0);int b=who; dfs1(a,-1,0);dfs1(b,-1,1); umax(dia,mx);dfs2(i,-1); v.pb(mn);mn=INF; } sort(all(v));reverse(all(v)); if(int(v.size())==1) return dia; if(int(v.size())==2) return max(dia,v[0]+v[1]+l); return max(dia,max(v[0]+v[1]+l,v[1]+v[2]+l+l)); }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:43:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   43 |  if(n==1)return 0;int dia=0;
      |  ^~
dreaming.cpp:43:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   43 |  if(n==1)return 0;int dia=0;
      |                   ^~~
dreaming.cpp:44:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |     for(int i=0;i<m;i++)
      |     ^~~
dreaming.cpp:46:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   46 |  vector<int>v;
      |  ^~~~~~
#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...