結果

問題 No.1 道のショートカット
ユーザー aa
提出日時 2018-06-11 21:02:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,312 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 110,296 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-22 13:19:42
合計ジャッジ時間 6,698 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
4,380 KB
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 2 ms
4,376 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecll> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

const int MAX_V = 64;

struct edge{int to, cost;};

//V := number of nodes
//G := adj
int V;
vector<edge> adj[MAX_V];
mat adj2 (MAX_V, vec (MAX_V, 0));
int d[MAX_V], pre[MAX_V], rev[MAX_V];
void dijkstra(int s){

	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+V, INF);
	fill(pre, pre+V, -1);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		rep((int)adj[v].size(), i) {
			edge e = adj[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));
				pre[e.to] = v;
			}
		}
	}
}


void solve(void){
	int C, E;
	cin >> V >> C >> E;
	vec ss(V), ts(V), ys(V), ms(V);
	rep(E, i)
	{
		cin >> ss[i];
		ss[i]--;
	}
	rep(E, i)
	{
		cin >> ts[i];
		ts[i]--;
		rev[ts[i]]++;
	}
	rep(E, i) cin >> ys[i];
	rep(E, i) cin >> ms[i];

	rep(E, i)
	{
		adj[ss[i]].pb((edge{ts[i], ms[i]}));
		adj2[ss[i]][ts[i]] = ys[i];
	}

	while(1)
	{

		dijkstra(0);

		if (d[V-1] == INF)
		{
			cout << -1 << endl;
			return;
		}

		int p = V-1, cost = 0;
		while (pre[p] != -1)
		{
			cost += adj2[pre[p]][p];
			p = pre[p];
		}

		//cout << cost << endl;

		if (cost <= C && p == 0)
		{
			cout << d[V-1] << endl;
			return;
		}

		if (!p)
		{
			cout << -1 << endl;
			return;
		}

		p = V-1;

		while (pre[p] != -1)
		{
			if (rev[p] > 1)
			{
				rev[p]--;
				vector <edge> newadj;
				rep(E, i)
				{
					if (ss[i] == pre[p] && ts[i] != p)
					{
						newadj.pb((edge{p, ms[i]}));
					}
				}
				swap(newadj, adj[pre[p]]);
				break;
			}
			p = pre[p];
		}

		if (p == 0)
		{
			cout << -1 << endl;
			return;
		}
	}

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0