結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
publfl
|
| 提出日時 | 2020-11-27 22:31:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,407 bytes |
| コンパイル時間 | 966 ms |
| コンパイル使用メモリ | 71,116 KB |
| 実行使用メモリ | 37,760 KB |
| 最終ジャッジ日時 | 2024-07-26 19:52:15 |
| 合計ジャッジ時間 | 6,133 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 32 |
ソースコード
#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> > 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);
}
publfl