結果

問題 No.2805 Go to School
ユーザー kino0402kino0402
提出日時 2024-07-12 22:03:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 5,314 bytes
コンパイル時間 3,768 ms
コンパイル使用メモリ 240,132 KB
実行使用メモリ 22,064 KB
最終ジャッジ日時 2024-07-16 01:39:40
合計ジャッジ時間 10,327 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 169 ms
16,768 KB
testcase_05 AC 214 ms
13,828 KB
testcase_06 AC 111 ms
9,216 KB
testcase_07 AC 102 ms
9,268 KB
testcase_08 AC 182 ms
14,336 KB
testcase_09 AC 110 ms
9,088 KB
testcase_10 AC 113 ms
9,088 KB
testcase_11 AC 356 ms
20,692 KB
testcase_12 AC 213 ms
14,288 KB
testcase_13 AC 307 ms
17,924 KB
testcase_14 AC 42 ms
6,272 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 150 ms
11,136 KB
testcase_19 AC 94 ms
8,576 KB
testcase_20 AC 250 ms
15,364 KB
testcase_21 AC 324 ms
19,948 KB
testcase_22 AC 126 ms
11,008 KB
testcase_23 AC 211 ms
14,076 KB
testcase_24 AC 215 ms
13,824 KB
testcase_25 AC 61 ms
8,640 KB
testcase_26 AC 233 ms
22,064 KB
testcase_27 AC 156 ms
16,640 KB
testcase_28 AC 13 ms
7,168 KB
testcase_29 AC 24 ms
7,808 KB
testcase_30 AC 84 ms
12,656 KB
testcase_31 AC 113 ms
10,496 KB
testcase_32 AC 227 ms
18,176 KB
testcase_33 AC 266 ms
18,992 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 105 ms
9,088 KB
testcase_37 AC 110 ms
10,240 KB
testcase_38 AC 213 ms
15,616 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:140:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  140 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all> 
using namespace std;
using namespace atcoder;
using ll=long long;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ketasuu cout << fixed << setprecision(10);
#define speedup std::cin.tie(0)->sync_with_stdio(0);
#define _GLIBCXX_DEBUG //優先度付きキュー使って時間制限厳しい場合コメントアウト
//#define int ll
#define int_max 2147483647
#define int_min -2147483647
#define uint_max 4294967295
#define ll_max 9223372036854775807
#define ll_min -9223372036854775807
#define ull_max 18446744073709551615
#define rep(i,n) for(ll i=0;i<(n);i++)
#define reps(i,n) for(ll i=1;i<=(n);i++)
#define REP(i,j,n) for(ll i=(j);i<(n);i++)
#define all(a) (a).begin(), (a).end()
#define repc(i,n,A) rep(i,n)cin>>A[i]
#define REPC(i,j,n,A) REP(i,j,n)cin>>A[i]
#define repc2(i,n,A,B) rep(i,n)cin>>A[i]>>B[i]
#define REPC2(i,j,n,A,B) REP(i,j,n)cin>>A[i]>>B[i]
#define repc2vec(i,j,a,b,A) rep(i,a)rep(j,b)cin>>A[i][j]
#define REPC2VEC(i,j,k,a,b,A) REP(i,k,a)REP(j,k,b)cin>>A[i][j]
#define repair(i,n,A) rep(i,n)cin>>A[i].F>>A[i].S
#define REPAIR(i,j,n,A) REP(i,j,n)cin>>A[i].F>>A[i].S
#define ST(A) sort(all(A))
#define RV(A) reverse(all(A))
#define juufuku(A) A.erase(unique(all(A)),A.end());
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define Endl endl
#define F first
#define S second
#define yes(b) ((b)?"yes":"no")
#define Yes(b) ((b)?"Yes":"No")
#define YES(b) ((b)?"YES":"NO")
#define TA(b) ((b)?"Takahashi":"Aoki")
#define AB(b) ((b)?"Alice":"Bob")
using vecll=vector<ll>; using vecst=vector<string>; using vecch=vector<char>;
using vecll2=vector<vecll>; using vecst2=vector<vecst>; using pll=pair<ll,ll>;
using vecch2=vector<vecch>; using vecpll=vector<pll>; using vecpll2=vector<vecpll>;
using vecbo=vector<bool>; using vecbo2=vector<vecbo>;
using vecdo=vector<double>; using vecdo2=vector<vecdo>;
template <typename T> inline T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}//最大公約数
template <typename T> inline T lcm(T a,T b){return (a*b)/gcd(a,b);}//最小公倍数
template <typename T>
bool chmax(T &a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a,const T& b){
  if(a>b){
    a=b;  // aをbで更新
    return true;
  }
  return false;
}
ll max(int a,ll b){return max((ll)a,b);}
ll max(ll a,int b){return max((ll)b,a);}
ll min(int a,ll b){return min((ll)a,b);}
ll min(ll a,int b){return min((ll)b,a);}
vecll DX={0,1,0,-1,1,1,-1,-1};
vecll DY={1,0,-1,0,1,-1,1,-1};
ll mod=998244353;
ll MOD=1000000007;
ll INF=1e10;
//ここからコード入力(関数使用時用)
//関数
ll randint(ll a,ll b){return a+rand()%(b-a+1);}
double randouble(){return 1.0*rand()/RAND_MAX;}
/*ll nibutan(ll K){
  //二分探索 .size()=要素数 [m]の前配列名
    ll ng=-1;
    ll ok=.size();
    while(ok-ng>1){
        ll m=(ng+ok)/2;
        if([m]<K)ok=m;
        else ng=m;
    }
    return ok;
}*/
vecpll soinsuubunkai(ll N){
  vecpll res;
  for(ll a=2;a*a<=N;a++){
    if(N%a!=0)continue;
    int ex=0; // 指数
    // 割れる限り割り続ける
    while(N%a==0){
      ex++;
      N/=a;
    }
    // その結果を push
    res.pb({a,ex});
  }
    // 最後に残った数について
  if(N!=1)res.pb({N,1});
  return res;
  //N=6 {2,1} {3,1}(2^1+3^1)のようになる autoで受け取ろう
}
/*//コンビネーション
ll C_MAX=510000;
vecll fac(C_MAX);
vecll finv(C_MAX);
vecll inv(C_MAX);
// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  REP(i,2,C_MAX){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}

//二項係数計算
ll COM(ll n,ll k){
  if(n<k)return 0;
  if(n<0||k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
void kitaitimod(ll a,ll b){
  //a/b
  ll denominator=inv_mod(b,mod);
  cout<<a*denominator%mod<<endl;
  return;
}*/
//ここからコード入力(   ´・ω・`     )
main(){
  ll A,B,C,D,E,tmp1,tmp2,tmp3,ans=ll_max;
  cin>>A>>B>>C>>D>>E;
  vecpll2 G(A);
  rep(i,B){
    cin>>tmp1>>tmp2>>tmp3;
    G[tmp1-1].pb(mp(tmp2-1,tmp3));
    G[tmp2-1].pb(mp(tmp1-1,tmp3));
  }
  vecll dis1(A,ll_max);
  vecll dis2(A,ll_max);
  vecbo ok1(A);
  vecbo ok2(A);
  priority_queue<pll,vecpll,greater<pll>>Q;
  dis1[0]=0;
  Q.push(mp(0,0));
  while(!Q.empty()){
    ll pos=Q.top().S;
    Q.pop();
    if(ok1[pos]==true)continue;
    ok1[pos]=true;
    rep(i,G[pos].size()){
      if(dis1[G[pos][i].F]>dis1[pos]+G[pos][i].S){
        dis1[G[pos][i].F]=dis1[pos]+G[pos][i].S;
        Q.push(mp(dis1[G[pos][i].F],G[pos][i].F));
      }
    }
  }
  dis2[A-1]=0;
  Q.push(mp(0,A-1));
  while(!Q.empty()){
    ll pos=Q.top().S;
    Q.pop();
    if(ok2[pos]==true)continue;
    ok2[pos]=true;
    rep(i,G[pos].size()){
      if(dis2[G[pos][i].F]>dis2[pos]+G[pos][i].S){
        dis2[G[pos][i].F]=dis2[pos]+G[pos][i].S;
        Q.push(mp(dis2[G[pos][i].F],G[pos][i].F));
      }
    }
  }
  /*rep(i,A)cout<<dis1[i]<<" ";
  cout<<endl;
  rep(i,A)cout<<dis2[i]<<" ";*/
  vecll F(C);
  repc(i,C,F);
  rep(i,C){
    if(dis1[F[i]-1]<=D+E-1&&dis2[F[i]-1]!=ll_max){
      ans=min(ans,max(dis1[F[i]-1]+1,D+1)+dis2[F[i]-1]);
    }
  }
  cout<<((ans==ll_max)?-1:ans)<<endl;
}
0