Submission #745641

#TimeUsernameProblemLanguageResultExecution timeMemory
745641Username4132Rail (IOI14_rail)C++14
30 / 100
299 ms98848 KiB
#include "rail.h" #include<iostream> #include<vector> using namespace std; using pii = pair<int, int>; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define PB push_back #define F first #define S second const int MAXN=5010, INF=1000000010; int *rel, *res; int n, dis[MAXN][MAXN]; bool vis[MAXN]; vector<pii> g[MAXN]; void dfs(int v){ vis[v]=true; for(pii to:g[v]) if(!vis[to.F]){ if(res[v]==1) rel[to.F]=rel[v]+to.S; else rel[to.F]=rel[v]-to.S; res[to.F] = res[v]==1? 2 : 1; dfs(to.F); } } void findLocation(int N, int first, int location[], int stype[]) { n=N; forn(i, n) forsn(j, i, n) dis[i][j]=dis[j][i]=getDistance(i, j); forn(i, n){ int mn=INF, ind=-1; forn(j, n) if(j!=i && mn>dis[i][j]) mn=dis[i][j], ind=j; g[i].PB({ind, mn}), g[ind].PB({i, mn}); } rel=location, res=stype; rel[0]=first, res[0]=1; dfs(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...