結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー tkmst201tkmst201
提出日時 2021-07-11 10:47:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 3,000 ms
コード長 1,808 bytes
コンパイル時間 2,805 ms
コンパイル使用メモリ 220,920 KB
実行使用メモリ 33,056 KB
最終ジャッジ日時 2023-09-14 20:07:15
合計ジャッジ時間 18,687 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 48 ms
14,404 KB
testcase_05 AC 163 ms
23,644 KB
testcase_06 AC 58 ms
11,964 KB
testcase_07 AC 74 ms
16,448 KB
testcase_08 AC 125 ms
10,864 KB
testcase_09 AC 46 ms
6,264 KB
testcase_10 AC 60 ms
15,864 KB
testcase_11 AC 84 ms
15,188 KB
testcase_12 AC 133 ms
20,160 KB
testcase_13 AC 42 ms
9,816 KB
testcase_14 AC 46 ms
14,300 KB
testcase_15 AC 16 ms
6,096 KB
testcase_16 AC 65 ms
18,736 KB
testcase_17 AC 29 ms
4,776 KB
testcase_18 AC 163 ms
20,912 KB
testcase_19 AC 72 ms
12,452 KB
testcase_20 AC 30 ms
5,016 KB
testcase_21 AC 81 ms
24,184 KB
testcase_22 AC 83 ms
19,560 KB
testcase_23 AC 89 ms
8,776 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 6 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 6 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 11 ms
4,380 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 8 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 4 ms
4,376 KB
testcase_43 AC 6 ms
4,376 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 3 ms
4,780 KB
testcase_46 AC 4 ms
4,380 KB
testcase_47 AC 7 ms
4,520 KB
testcase_48 AC 10 ms
7,248 KB
testcase_49 AC 12 ms
5,248 KB
testcase_50 AC 19 ms
7,200 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 20 ms
7,308 KB
testcase_53 AC 9 ms
5,116 KB
testcase_54 AC 3 ms
4,376 KB
testcase_55 AC 24 ms
6,688 KB
testcase_56 AC 3 ms
4,380 KB
testcase_57 AC 14 ms
5,380 KB
testcase_58 AC 14 ms
5,168 KB
testcase_59 AC 4 ms
4,376 KB
testcase_60 AC 4 ms
4,376 KB
testcase_61 AC 6 ms
4,380 KB
testcase_62 AC 19 ms
4,912 KB
testcase_63 AC 7 ms
4,376 KB
testcase_64 AC 156 ms
22,032 KB
testcase_65 AC 3 ms
4,376 KB
testcase_66 AC 80 ms
33,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, S, T, K;
	cin >> N >> S >> T >> K; --S; --T;
	vector<int> X(N);
	REP(i, N) scanf("%d", &X[i]);
	int M;
	cin >> M;
	vector<vector<pii>> g(N);
	REP(i, M) {
		int a, b, y;
		scanf("%d %d %d", &a, &b, &y);
		--a; --b;
		g[a].emplace_back(b, y + X[a]);
	}
	
	vector dist(N, vector<ll>(K, longINF));
	vector prv(N, vector<pii>(K, {-1, -1}));
	// r 回 (chmin(r, K - 1)) dist, vertex
	using tup = tuple<int, ll, int>;
	priority_queue<tup, vector<tup>, greater<tup>> pq;
	dist[S][0] = 0;
	pq.emplace(0, 0, S);
	while (!pq.empty()) {
		auto [k, d, u] = pq.top(); pq.pop();
		if (dist[u][k] != d) continue;
		for (auto [v, l] : g[u]) {
			const int nk = min(k + 1, K - 1);
			const ll nd = d + l;
			if (chmin(dist[v][nk], nd)) {
				prv[v][nk] = {u, k};
				pq.emplace(nk, nd, v);
			}
		}
	}
	if (dist[T][K - 1] == longINF) puts("Impossible");
	else {
		puts("Possible");
		cout << dist[T][K - 1] + X[T] << endl;
		
		int u = T, k = K - 1;
		vector<int> ans;
		while (u != -1) {
			ans.emplace_back(u);
			auto [nu, nk] = prv[u][k];
			u = nu; k = nk;
		}
		reverse(ALL(ans));
		cout << ans.size() << endl;
		REP(i, ans.size()) printf("%d%c", ans[i] + 1, " \n"[i + 1 == ans.size()]);
	}
}
0