結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
yukitf
|
| 提出日時 | 2020-07-22 11:38:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,204 bytes |
| コンパイル時間 | 1,868 ms |
| コンパイル使用メモリ | 188,192 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-08 05:31:18 |
| 合計ジャッジ時間 | 2,897 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 12 WA * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define RREP(i, n) for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define mp make_pair
#define mt make_tuple
#define pb push_back
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
int N, C, V;
vector<vector<pi>> G;
int idx = 0;
vi sorted;
vector<bool> visited;
void dfs(int n)
{
visited[n] = true;
REP(i, N)
{
pi p = G[n][i];
if(p.first != INF && p.second != INF)
{
if(!visited[i])dfs(i);
}
}
sorted[idx++] = n;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cin >> N >> C >> V;
vi S(V), T(V), Y(V), M(V);
REP(i, V) cin >> S[i], S[i]--;
REP(i, V) cin >> T[i], T[i]--;
REP(i, V) cin >> Y[i];
REP(i, V) cin >> M[i];
G.resize(N, vector<pi>(N, mp(INF, INF)));
REP(i, V)
{
G[S[i]][T[i]] = mp(Y[i], M[i]);
}
// トポロジカルソート
sorted.resize(N);
visited.resize(N, false);
dfs(0);
reverse(ALL(sorted));
//REP(i, N) cout << sorted[i] << " ";
//cout << endl;
vector<vi> time(N, vi(C+1, INF));
time[sorted[0]][C] = 0;
REP(i, N)
{
int n = sorted[i];
REP(j, N)
{
pi p = G[n][j];
REP(c, C+1)
{
if(c >= p.first) chmin(time[j][c-p.first], time[n][c] + p.second);
}
}
}
int m = 0;
REP(i, N) if(sorted[i] == N-1) m = i;
int ans = INF;
REP(c, C+1)
{
chmin(ans, time[m][c]);
}
if(ans >= INF) cout << -1 << endl;
else cout << ans << endl;
}
yukitf