結果

問題 No.807 umg tours
ユーザー ttttanttttan
提出日時 2019-03-31 01:21:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,073 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 176,284 KB
実行使用メモリ 23,132 KB
最終ジャッジ日時 2024-04-28 20:28:07
合計ジャッジ時間 8,474 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 306 ms
12,288 KB
testcase_21 AC 312 ms
12,800 KB
testcase_22 AC 131 ms
7,680 KB
testcase_23 AC 98 ms
6,656 KB
testcase_24 AC 305 ms
17,760 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tl;
ll inf=1000000000000000000;
struct edge{ll len,ma,num;};
bool cmp(edge a,edge b){
  if(a.len!=b.len)return a.len<b.len;
  else{
    if(a.ma!=b.ma)return a.ma<b.ma;
    else{
      if(a.num!=b.num)return a.num<b.num;
      return true;
    }
  }
}
int main(){
    ll n,m;cin>>n>>m;
    vector<pll> v[n+1];
    for(ll i=0;i<m;i++){
        ll a,b,c;cin>>a>>b>>c;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    ll d[n+1],da[n+1];
    fill(d,d+n+1,inf);
    fill(da,da+n+1,inf);
    priority_queue<pll,vector<pll>,greater<pll>> q;
    q.push(make_pair(0,1));
    bool used[n+1];
    fill(used,used+n+1,false);
    d[1]=0;
    while(q.size()>0){
        pll p=q.top();q.pop();
        ll pf=p.first,ps=p.second;
        if(used[ps])continue;
        used[ps]=true;
        for(ll i=0;i<v[ps].size();i++){
            ll now=v[ps][i].first;
            ll dis=v[ps][i].second;
            if(used[now])continue;
            if(d[now]>dis+pf){
                d[now]=dis+pf;
                q.push(make_pair(dis+pf,now));
            }
        }
        
    }
  
    fill(used,used+n+1,false);
    
    priority_queue<tl,vector<tl>,greater<tl>> qq;
    qq.push(make_tuple(0,0,1));
    da[1]=0;
    while(qq.size()>0){
        tl t=qq.top();qq.pop();
        ll tf=get<0>(t),ts=get<1>(t),tt=get<2>(t);
        if(used[tt])continue;
        used[tt]=true;
      //cout<<tf<<" "<<ts<<" "<<tt<<endl;
        for(int i=0;i<v[tt].size();i++){
            ll now=v[tt][i].first;
            ll dis=v[tt][i].second;
            ll u=dis+tf;
          ll y=ts;
          if(used[now])continue;
            if(ts<dis){
                u-=dis-ts;
                y=dis;
            }
            if(da[now]>u){
                da[now]=u;
                qq.push(make_tuple(u,y,now));
            }
        }
    }
    for(ll i=1;i<=n;i++)cout<<d[i]+da[i]<<endl;
  for(ll i=1;i<=n;i++){
    //cout<<d[i]<<" "<<da[i]<<endl;
  }
}
0