結果
| 問題 | No.1301 Strange Graph Shortest Path |
| コンテスト | |
| ユーザー |
ゆきのん
|
| 提出日時 | 2020-12-01 06:37:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,421 bytes |
| 記録 | |
| コンパイル時間 | 2,098 ms |
| コンパイル使用メモリ | 184,472 KB |
| 実行使用メモリ | 27,456 KB |
| 最終ジャッジ日時 | 2024-09-13 02:48:14 |
| 合計ジャッジ時間 | 10,536 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll mod=998244353;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
struct edge {int to;ll cost;};
const int M_N=300000;
vector<edge> G[M_N+1];
struct Dijkstra{
ll d[M_N+1];
ll b[M_N+1];
void init(int n){
fill(d,d+n,LINF);
fill(b,b+n,0);
}
void dijkstra(int s){
priority_queue<P,vector<P>,greater<P>> que;
que.push(P(0, s));
d[s] = 0;
while(!que.empty()){
P p=que.top();
que.pop();
int v=p.second;
if(d[v]<p.first) continue;
for(int i=0;i<G[v].size();i++){
edge e=G[v][i];
if(d[e.to]>d[v]+e.cost){
d[e.to]=d[v]+e.cost;
que.push(P(d[e.to],e.to));
b[e.to]=v;
}
}
}
}
};
int main(){
int n,m;cin >> n >> m;
vector<int> a(m);
auto b = a;
auto c = a;
auto d = a;
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
a[i]--,b[i]--;
G[a[i]].pb({b[i], c[i]});
G[b[i]].pb({a[i], c[i]});
}
Dijkstra ds;
ds.init(n);
ds.dijkstra(0);
ll ans = ds.d[n-1];
for (int i = 0; i < n; i++) {
G[i].clear();
}
int now = n - 1;
set<P> st;
while(now != 0){
int to = ds.b[now];
st.insert({now, to});
st.insert({to, now});
now = to;
}
for (int i = 0; i < m; i++) {
if(st.find({a[i], b[i]}) != st.end()){
G[a[i]].pb({b[i], d[i]});
G[b[i]].pb({a[i], d[i]});
}
else{
G[a[i]].pb({b[i], c[i]});
G[b[i]].pb({a[i], c[i]});
}
}
ds.init(n);
ds.dijkstra(0);
ans += ds.d[n-1];
cout << ans << endl;
return 0;
}
ゆきのん