結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
log_K
|
| 提出日時 | 2019-07-23 22:34:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,809 bytes |
| コンパイル時間 | 1,629 ms |
| コンパイル使用メモリ | 187,140 KB |
| 実行使用メモリ | 813,908 KB |
| 最終ジャッジ日時 | 2024-07-08 05:13:46 |
| 合計ジャッジ時間 | 4,642 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 MLE * 1 -- * 32 |
ソースコード
#include <bits/stdc++.h>
//#include <rng_58>
//#include <chokudai>
//#include <tourist>
using namespace std;
// Macro and Macro Functions
#define rep(a, b) for(int a = 0; a < b; ++a)
#define REP(a, b, c) for(int a = b; a < c; ++a)
#define drep(a, b, c) for(int a=0,b=0;b<c?:(b=0,++a<c);++b)
#define int long long
#define between(n,_min,_max) if(_min<=n&&n<=_max)
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MOD 1000000007
#define Beg(a) (a).begin()
#define End(a) (a).end()
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define ALLIN(a) rep(nanika,a.size()) cin>>a[nanika]
#define ALLINDE(a) rep(kyawa,a.size()){cin>>a[kyawa]; --a[kyawa];}
#define YN(a) do{if(a) cout<<"YES"; else cout<<"NO";}while(0)
#define Yn(a) do{if(a) cout<<"Yes"; else cout<<"No";}while(0)
#define yn(a) do{if(a) cout<<"yes"; else cout<<"no";}while(0)
#define spa " "
#define dspa " "
#define ctoi(c) (c)-'0'
#define altoi(a) (a)-'a'
#define fi first
#define se second
#define dvec(type,name,row,column,value) vector<vector<type>> name(row,vector<type>(column,value))
// List of using
using ll = signed long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pong = pair<long, long>;
using tint = tuple<int, int, int>;
using tong = tuple<long, long, long>;
using vint = vector<int>;
using vll = vector<long long>;
using vbol = vector<bool>;
using vstr = vector<string>;
using vull = vector<unsigned long long>;
using dvin = vector<vector<int>>;
using dvbo = vector<vector<bool>>;
using mint = map<int,int>;
// Common Variable
bool DEBUG=false;
unsigned long long INF=(1<<31);
void print(){
cout<<'\n';
}
template<class HEAD,class... TAIL>
void print(HEAD&& head,TAIL&&... tail){
cout<<head<<spa;
print(forward<TAIL>(tail)...);
}
template<class HEAD,class... TAIL>
void dprint(HEAD&& head,TAIL&&... tail){
cout<<"Debug : "<<head<<spa;
print(forward<TAIL>(tail)...);
}
void scan(){}
template<class HEAD,class... TAIL>
void scan(HEAD&& head,TAIL&&... tail){
cin>>head;
scan(forward<TAIL>(tail)...);
}
template<typename t>
void print(vector<t> &v){
rep(i,v.size()){
cout<<v[i]<<spa;
}
cout<<endl;
}
template<typename t, typename u>
void print(vector<pair<t,u>> &v){
rep(i,v.size()){
cout<<i<<" : "<<v[i].first<<" "<<v[i].second<<endl;
}
}
int RepeatSquaring(int N, int P, int M){
if(P==0) return 1;
if(P%2==0){
int t = RepeatSquaring(N, P/2, M);
return t*t % M;
}
return N * RepeatSquaring(N, P-1, M);
}
//--------------------------------
// Template Place
template<typename T>
struct edge{int to; T cost,tt;};
template<typename T>
class Graph{
public :
int size;
vector<vector<edge<T>>> Graph;
vector<T> dis;
vector<T> prev;
vector<vector<T>> Tdis;
void init(int n){
size=n;
Graph.resize(size);
dis.resize(size);
prev.resize(size);
}
void add(int x,int y,T z,T zz){
Graph[x].emplace_back((edge<T>){y,z,zz});
}
};
//--------------------------------
// int dx[]={ 1, 0,-1, 0};
// int dy[]={ 0,-1, 0, 1};
signed main(){
int n,c,v; cin>>n>>c>>v;
vint s(v),t(v),y(v),m(v);
ALLINDE(s); ALLINDE(t); ALLIN(y); ALLIN(m);
Graph<int> gr; gr.init(n);
rep(i,v){
gr.add(s[i],t[i],y[i],m[i]);
}
// 現在位置、現在の必要経費、現在の経過時間
queue<tint> q;
int ans=(1<<30);
q.emplace(0,0,0);
while(!q.empty()){
int tp,tc,tt; tie(tp,tc,tt)=q.front(); q.pop();
//print(tp+1,tc,tt);
if(tp==n-1){
ans=min(ans,tt);
continue;
}
rep(i,gr.Graph[tp].size()){
if(tc+gr.Graph[tp][i].cost>c) continue;
q.emplace(gr.Graph[tp][i].to,tc+gr.Graph[tp][i].cost,tt+gr.Graph[tp][i].tt);
}
}
if(ans==(1<<30)) cout<<-1<<endl;
else cout<<ans<<endl;
}
log_K