Submission #399682

#TimeUsernameProblemLanguageResultExecution timeMemory
399682JasiekstrzRail (IOI14_rail)C++17
56 / 100
2070 ms99012 KiB
#include<bits/stdc++.h>
#include "rail.h"
#define fi first
#define se second
using namespace std;
const int NN=5e3;
const int INF=1e9+7;
struct Edge
{
	int x,y,c;
	bool operator<(const Edge &oth) const
	{
		if(c==oth.c)
		{
			if(y==oth.y)
				return x<oth.x;
			return y<oth.y;
		}
		return c<oth.c;
	}
};
int d[NN+10][NN+10];
bool vis[NN+10];
Edge bst[NN+10];
set<Edge> pq;
void add_edges(int x,int n)
{
	for(int y=0;y<n;y++)
	{
		Edge tmp={x,y,d[x][y]};
		if(!vis[y] && tmp<bst[y])
		{
			pq.erase(bst[y]);
			bst[y]=tmp;
			pq.insert(bst[y]);
		}
	}
	return;
}
void findLocation(int N,int first,int location[],int stype[])
{
	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)
			d[i][j]=d[j][i]=getDistance(i,j);
	}
	for(int i=1;i<N;i++)
	{
		bst[i]={i,i,INF};
		pq.insert(bst[i]);
	}
	location[0]=first;
	stype[0]=1;
	vis[0]=true;
	add_edges(0,N);
	while(!pq.empty())
	{
		auto v=(*pq.begin());
		pq.erase(pq.begin());
		if(vis[v.y])
			continue;
		if(stype[v.x]==1)
		{
			stype[v.y]=2;
			location[v.y]=location[v.x]+v.c;
		}
		else
		{
			stype[v.y]=1;
			location[v.y]=location[v.x]-v.c;
		}
		vis[v.y]=true;
		add_edges(v.y,N);
	}
	//for(int i=0;i<N;i++)
	//	cerr<<i<<": "<<stype[i]<<" "<<location[i]<<"\n";
	return;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...