結果

問題 No.1301 Strange Graph Shortest Path
ユーザー publflpublfl
提出日時 2020-11-27 22:33:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,502 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 70,868 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2023-10-09 21:35:14
合計ジャッジ時間 21,980 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,412 KB
testcase_01 AC 3 ms
5,424 KB
testcase_02 WA -
testcase_03 AC 493 ms
28,872 KB
testcase_04 AC 702 ms
34,368 KB
testcase_05 AC 531 ms
31,824 KB
testcase_06 AC 632 ms
31,876 KB
testcase_07 AC 594 ms
31,528 KB
testcase_08 AC 487 ms
29,120 KB
testcase_09 AC 595 ms
30,676 KB
testcase_10 WA -
testcase_11 AC 634 ms
32,448 KB
testcase_12 AC 643 ms
32,732 KB
testcase_13 AC 592 ms
32,364 KB
testcase_14 AC 569 ms
30,232 KB
testcase_15 AC 564 ms
30,320 KB
testcase_16 AC 680 ms
34,484 KB
testcase_17 AC 618 ms
33,016 KB
testcase_18 AC 548 ms
30,600 KB
testcase_19 AC 617 ms
32,176 KB
testcase_20 AC 625 ms
31,988 KB
testcase_21 AC 606 ms
32,444 KB
testcase_22 AC 638 ms
32,856 KB
testcase_23 AC 584 ms
32,620 KB
testcase_24 AC 623 ms
32,252 KB
testcase_25 AC 670 ms
33,920 KB
testcase_26 AC 593 ms
31,668 KB
testcase_27 AC 603 ms
32,204 KB
testcase_28 AC 516 ms
30,892 KB
testcase_29 WA -
testcase_30 AC 669 ms
33,544 KB
testcase_31 AC 682 ms
33,680 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 708 ms
33,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

std::vector<int> V[100010];
std::map< std::pair<int,int> , int > M,M2;
std::priority_queue< std::pair<long long int,int> , std::vector< std::pair<long long int,int> > , std::greater< std::pair<long long int, int > > > Q;
long long int dist[100010];
int prev[100010];
long long int MAX = 1;
int a;

long long int func(int start, int end)
{
	for(int i=1;i<=a;i++) dist[i] = MAX;
	Q.push(std::make_pair(0,start));
	dist[start] = 0;
	
	while(!Q.empty())
	{
		long long int S = Q.top().first;
		int t = Q.top().second;
		Q.pop();
		if(dist[t]!=S) continue;
		
		for(int i=0;i<V[t].size();i++)
		{
			if(dist[V[t][i]]>S+M[std::make_pair(t,V[t][i])])
			{
				dist[V[t][i]] = S+M[std::make_pair(t,V[t][i])];
				prev[V[t][i]] = t;
				Q.push(std::make_pair(S+M[std::make_pair(t,V[t][i])],V[t][i]));
			}
		}
	}
	
	int p = end;
	while(p!=start)
	{
		M[std::make_pair(p,prev[p])] = M2[std::make_pair(p,prev[p])];
		M[std::make_pair(prev[p],p)] = M2[std::make_pair(p,prev[p])];
		p = prev[p];
		if(p==0) break;
	}
	return dist[end];
}
int main()
{
	for(int i=1;i<=15;i++) MAX*=10;
	
	int 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);
		V[d].push_back(c);
		M[std::make_pair(c,d)] = e;
		M[std::make_pair(d,c)] = e;
		M2[std::make_pair(c,d)] = f;
		M2[std::make_pair(d,c)] = f;
	}
	
	long long int S1 = func(1,a);
	long long int S2 = func(a,1);
	printf("%lld",S1+S2);
}
0