結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
tute7627
|
| 提出日時 | 2019-07-05 23:20:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,252 bytes |
| コンパイル時間 | 1,602 ms |
| コンパイル使用メモリ | 176,128 KB |
| 実行使用メモリ | 18,560 KB |
| 最終ジャッジ日時 | 2024-10-06 23:07:55 |
| 合計ジャッジ時間 | 6,369 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 5 WA * 20 TLE * 1 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
ll MAX_V = 3000; //頂点数
struct edge {
ll to;
ll cost;
};
//<最短距離, 頂点の番号>using P = pair<ll, ll>;
vector<vector<struct edge>> G(MAX_V); //隣接リスト
vector<ll> d(MAX_V); //各頂点への最短距離
void dijkstra(ll s) {
priority_queue<P, vector<P>, greater<P> > que;
fill(ALL(d), INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
ll v = p.second;
if (d[v] < p.first) continue;
for (ll i=0; i<G[v].size(); i++) {
struct 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));
}
}
}
}
int main(){
ll i,j,o;
ll res=-1,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
bool judge = true;
ll n,m,p,q,t;cin>>n>>m>>p>>q>>t;
vector<ll> u(m),v(m),a(m);
for(i=0;i<m;i++){
cin>>u[i]>>v[i]>>a[i];
struct edge e ={v[i],a[i]};
G[u[i]].push_back(e);
e ={u[i],a[i]};
G[v[i]].push_back(e);
}
vector<ll>dp(n+1),dq(n+1);
dijkstra(p);
for(i=1;i<=n;i++)dp[i]=d[i];
dijkstra(q);
for(i=1;i<=n;i++)dq[i]=d[i];
if(dp[1]>dq[1]){
queue<ll> r;
r.push(1);
while(!r.empty()){
buf=r.front();
chmax(res,t-max(2*dp[1],
dp[1]-dp[buf]+dq[buf]+dq[1])+dp[1]-dp[buf]);
if(dq[buf]<=dp[buf])
chmax(res,t-2*dq[1]+2*(dp[1]-dp[buf]));
for(i=0;i<G[buf].size();i++){
struct edge e=G[buf][i];
if(dp[buf]-dp[e.to]==e.cost)
r.push(e.to);
}
r.pop();
}
}
else{
queue<ll> r;
r.push(1);
while(!r.empty()){
buf=r.front();
//cout<<buf spa res spa
//2*dq[1] spa dq[1]-dq[buf]+dp[buf]+dp[1]<<endl;
chmax(res,t-max(2*dq[1],
dq[1]-dq[buf]+dp[buf]+dp[1])+dq[1]-dq[buf]);
if(dp[buf]<=dq[buf])
chmax(res,t-2*dq[1]+2*(dq[1]-dq[buf]));
for(i=0;i<G[buf].size();i++){
struct edge e=G[buf][i];
if(dq[buf]-dq[e.to]==e.cost)
r.push(e.to);
}
r.pop();
}
}
if(dp[1]+dq[1]+dp[q]<=t)cout<<t<<endl;
else if(2*dp[1]<=t&&2*dq[1]<=t)cout<<res<<endl;
else cout<<-1<<endl;
return 0;
}
tute7627