結果
| 問題 |
No.1545 [Cherry 2nd Tune N] Anthem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-26 14:54:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,102 bytes |
| コンパイル時間 | 2,279 ms |
| コンパイル使用メモリ | 184,352 KB |
| 実行使用メモリ | 834,756 KB |
| 最終ジャッジ日時 | 2024-12-14 21:41:38 |
| 合計ジャッジ時間 | 78,448 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 TLE * 12 MLE * 7 |
ソースコード
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define logn long
#define lnog long
#define lgon long
#define itn int
typedef pair<long long, long long> P;
const long logn INF = 1e18;
int main() {
long long N, S, T, K; cin >> N >> S >> T >> K;
vector<long long>X(N + 1);
for (long long i = 1; i <= N; i++) {
cin >> X[i];
}
long long M; cin >> M;
vector<vector<P>>E(N + 1);
for (long long i = 0; i < M; i++) {
long long A, B, Y; cin >> A >> B >> Y;
E[A].push_back({ B, Y });
}
vector<vector<long long>>DP(N + 1, vector<long long>(K + 1, INF));
DP[S][1] = X[S];
vector<vector<P>>Prev(N + 1, vector<P>(K + 1, { 0, 0 }));
priority_queue<pair<P, long long>, vector<pair<P, long long>>, greater<pair<P, long long>>>Q;
Q.push({ {S,1 }, 0});
while (!Q.empty()) {
pair<P, long long> R = Q.top(); Q.pop();
long long x = R.first.first, k = R.first.second, d = R.second;
if (DP[x][k] < d) continue;
//if (x == T && k == K) break;
long long L = min(K, k + 1);
for (const P &a : E[x]) {
long long y = a.first, m = a.second;
if (DP[x][k] + m + X[y] < DP[y][L]) {
DP[y][L] = DP[x][k] + m + X[y];
Prev[y][L] = { x, k };
Q.push({ {y, L}, DP[y][L] });
}
}
}
if (DP[T][K] >= INF) {
cout << "Impossible" << endl;
return 0;
}
long long x = T, k = K;
vector<long long>Z;
while (k > 0) {
Z.push_back(x);
P ans = Prev[x][k];
x = ans.first; k = ans.second;
}
cout << "Possible" << endl << DP[T][K] << endl << Z.size() << endl;
for (long long i = Z.size() - 1; i >= 0; i--) {
if (i != Z.size() - 1) cout << ' ';
cout << Z[i];
}
cout << endl;
}