結果

問題 No.1601 With Animals into Institute
ユーザー publflpublfl
提出日時 2021-07-10 14:11:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 278 ms / 3,000 ms
コード長 1,153 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 54,912 KB
実行使用メモリ 21,412 KB
最終ジャッジ日時 2024-07-02 02:17:05
合計ジャッジ時間 6,179 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <queue>
#define MAX (long long int)1e16

struct str{
	int first;
	int second;
	long long int third;
};
bool operator<(str a, str b)
{
	return a.third>b.third;
}
std::priority_queue<str> Q;
std::vector<str> V[200010];

long long int dist[200010][3];

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++)
	{
		int c,d,e,f;
		scanf("%d%d%d%d",&c,&d,&e,&f);
		V[c].push_back({d,e,f});
		V[d].push_back({c,e,f});
	}
	
	for(int i=1;i<=a;i++) dist[i][0] = dist[i][1] = MAX;
	
	Q.push({a,0,0});
	dist[0][0] = 0;
	
	while(!Q.empty())
	{
		str A = Q.top();
		Q.pop();
		if(dist[A.first][A.second]<A.third) continue;
		
		for(int i=0;i<V[A.first].size();i++)
		{
			str B = V[A.first][i];
			if(B.third==1)
			{
				if(dist[B.first][1]>A.third + B.second)
				{
					dist[B.first][1] = A.third + B.second;
					Q.push({B.first,1,A.third+B.second});
				}
			}
			else
			{
				if(dist[B.first][A.second]>A.third + B.second)
				{
					dist[B.first][A.second] = A.third + B.second;
					Q.push({B.first,A.second,A.third+B.second});
				}
			}
		}
	}
	
	for(int i=1;i<a;i++) printf("%lld\n",dist[i][1]);
}
0