이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |