This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "rail.h"
#define fi first
#define se second
using namespace std;
const int NN=5e3;
struct Edge
{
int x,y,c;
bool operator<(const Edge &oth) const
{
return c>oth.c;
}
};
int d[NN+10][NN+10];
bool vis[NN+10];
priority_queue<Edge> pq;
void add_edges(int x,int n)
{
for(int y=0;y<n;y++)
{
if(!vis[y])
pq.push({x,y,d[x][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);
}
location[0]=first;
stype[0]=1;
vis[0]=true;
add_edges(0,N);
while(!pq.empty())
{
auto v=pq.top();
pq.pop();
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |