結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー kotatsugamekotatsugame
提出日時 2020-05-29 21:35:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 92,888 KB
実行使用メモリ 26,036 KB
最終ジャッジ日時 2024-11-06 02:44:42
合計ジャッジ時間 8,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<queue>
using namespace std;
int N,M,X,Y;
int x[2<<17],y[2<<17];
vector<pair<int,double> >G[2<<17];
double dist[2<<17];
main()
{
	cin>>N>>M>>X>>Y;X--,Y--;
	for(int i=0;i<N;i++)
	{
		cin>>x[i]>>y[i];
	}
	for(int i=0;i<M;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		double c=hypot(x[u]-x[v],y[u]-y[v]);
		G[u].push_back(make_pair(v,c));
		G[v].push_back(make_pair(u,c));
	}
	for(int i=0;i<N;i++)dist[i]=1e150;
	dist[X]=0;
	priority_queue<pair<double,int> >P;
	P.push(make_pair(0,X));
	while(!P.empty())
	{
		double c=-P.top().first;
		int u=P.top().second;P.pop();
		if(dist[u]<c-1e-10)continue;
		for(pair<int,double>p:G[u])
		{
			int v=p.first;
			double nxt=c+p.second;
			if(dist[v]>nxt)
			{
				dist[v]=nxt;
				P.push(make_pair(-nxt,v));
			}
		}
	}
	cout<<fixed<<setprecision(16)<<dist[Y]<<endl;
}
0