結果

問題 No.1301 Strange Graph Shortest Path
ユーザー 沙耶花沙耶花
提出日時 2020-11-27 22:08:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,467 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 217,348 KB
実行使用メモリ 26,596 KB
最終ジャッジ日時 2023-10-10 21:42:06
合計ジャッジ時間 9,374 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 106 ms
17,196 KB
testcase_04 AC 198 ms
25,448 KB
testcase_05 AC 107 ms
17,628 KB
testcase_06 AC 180 ms
23,284 KB
testcase_07 AC 151 ms
20,828 KB
testcase_08 AC 105 ms
17,328 KB
testcase_09 AC 164 ms
22,580 KB
testcase_10 WA -
testcase_11 AC 173 ms
22,856 KB
testcase_12 AC 180 ms
23,452 KB
testcase_13 AC 139 ms
20,176 KB
testcase_14 AC 152 ms
21,560 KB
testcase_15 AC 149 ms
20,684 KB
testcase_16 AC 212 ms
25,832 KB
testcase_17 AC 160 ms
21,396 KB
testcase_18 AC 150 ms
19,636 KB
testcase_19 AC 178 ms
23,360 KB
testcase_20 AC 183 ms
24,312 KB
testcase_21 AC 158 ms
21,052 KB
testcase_22 AC 191 ms
24,924 KB
testcase_23 AC 145 ms
20,596 KB
testcase_24 AC 182 ms
24,028 KB
testcase_25 AC 188 ms
24,356 KB
testcase_26 AC 163 ms
21,616 KB
testcase_27 AC 170 ms
22,636 KB
testcase_28 AC 112 ms
17,844 KB
testcase_29 WA -
testcase_30 AC 183 ms
23,840 KB
testcase_31 AC 197 ms
24,840 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 152 ms
23,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
    7 | pair<long long,vector<int>> get(auto E){
      |                                 ^~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

pair<long long,vector<int>> get(auto E){
	vector<long long> dis(E.size(),Inf);
	dis[0] = 0LL;
	
	priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
	Q.emplace(0,0);
	vector<int> last(E.size(),-1);
	while(Q.size()>0){
		long long D = Q.top().first;
		int u = Q.top().second;
		Q.pop();
		if(D!=dis[u])continue;
		
		rep(i,E[u].size()){
			int v = E[u][i].first;
			long long DD = E[u][i].second;
			if(dis[v]>D+DD){
				dis[v] = D+DD;
				Q.emplace(D+DD,v);
				last[v] = u;
			}
		}
	}
	
	vector<int> ret(1,E.size()-1);
	while(ret.back()!=0){
		ret.push_back(last[ret.back()]);
	}
	
	return make_pair(dis.back(),ret);
}

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector E(N,vector<pair<int,long long>>());
	auto Ec = E;
	
	rep(i,M){
		int u,v,c,d;
		scanf("%d %d %d %d",&u,&v,&c,&d);
		u--;v--;
		
		E[u].emplace_back(v,c);
		E[v].emplace_back(u,c);
		Ec[u].emplace_back(v,d);
		Ec[v].emplace_back(u,d);
	}
	
	long long ans = 0LL;
	//cout<<'a'<<endl;
	auto ret = get(E);
	ans += ret.first;
	
	rep(i,ret.second.size()-1){
		int u = ret.second[i],v = ret.second[i+1];
		rep(j,E[u].size()){
			if(E[u][j].first==v)swap(E[u][j],Ec[u][j]);
		}
		
		rep(j,E[v].size()){
			if(E[v][j].first==u)swap(E[v][j],Ec[v][j]);
		}
	}
	
	ans += get(E).first;
	
	cout<<ans<<endl;
	
    return 0;
}
0