Submission #426918

#TimeUsernameProblemLanguageResultExecution timeMemory
426918AmineWeslatiDreaming (IOI13_dreaming)C++14
14 / 100
1066 ms14980 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int>vi; #define pb push_back #define sz(v) (int)v.size() typedef pair<int,int>pi; #define fi first #define se second typedef vector<pi>vpi; #define eb emplace_back #define FOR(i,a,b) for(int i=a; i<b; i++) #define ROF(i,a,b) for(int i=b-1; i>=a; i--) void ckmax(int &x, int y){x=max(x,y);} void ckmin(int &x, int y){x=min(x,y);} const int MX=1e5+10; int N,M; vpi adj[MX]; vi vis(MX,0); vi dist(MX); pi par[MX]; void dfs(int u){ vis[u]=1; for(auto it: adj[u]){ int v=it.fi,w=it.se; if(dist[v]==-1){ dist[v]=dist[u]+w; par[v]={u,w}; dfs(v); } } } int U,V,diam; void solve(int u){ FOR(i,0,N) dist[i]=-1; dist[u]=0; dfs(u); int v=u; FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; u=v; FOR(i,0,N) dist[i]=-1; dist[u]=0; dfs(u); v=u; FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; diam=dist[v]; tie(U,V)={u,v}; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { ::N=N; ::M=M; FOR(i,0,M){ int u=A[i],v=B[i],w=T[i]; adj[u].eb(v,w); adj[v].eb(u,w); } int ans=0; vi vec; FOR(i,0,N) if(!vis[i]){ solve(i); ckmax(ans,diam); int cur=0,mn=2e9; //cout << U << " " << V << endl; while(U!=V){ cur+=par[V].se; V=par[V].fi; ckmin(mn,max(diam-cur,cur)); } vec.pb(mn); } ckmax(ans,vec[0]+vec[1]+L); return ans; } /* 12 8 2 0 8 2 5 5 1 1 10 8 2 7 11 1 3 9 6 4 2 4 3 7 1 5 3 */ /* 12 10 5 0 0 0 1 1 3 7 7 5 5 1 2 3 4 5 6 8 9 10 11 2 3 1 4 1 6 5 5 5 5 */

Compilation message (stderr)

dreaming.cpp: In function 'void solve(int)':
dreaming.cpp:16:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:45:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
dreaming.cpp:16:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:52:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
#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...