結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー kwm_tkwm_t
提出日時 2021-06-17 18:09:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 3,000 ms
コード長 2,483 bytes
コンパイル時間 2,493 ms
コンパイル使用メモリ 187,516 KB
実行使用メモリ 35,820 KB
最終ジャッジ日時 2023-08-31 01:31:51
合計ジャッジ時間 18,925 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,080 KB
testcase_01 AC 4 ms
8,280 KB
testcase_02 AC 5 ms
8,080 KB
testcase_03 AC 4 ms
8,192 KB
testcase_04 AC 46 ms
18,116 KB
testcase_05 AC 134 ms
25,928 KB
testcase_06 AC 56 ms
15,888 KB
testcase_07 AC 66 ms
19,576 KB
testcase_08 AC 110 ms
15,576 KB
testcase_09 AC 43 ms
10,324 KB
testcase_10 AC 58 ms
18,772 KB
testcase_11 AC 75 ms
18,776 KB
testcase_12 AC 114 ms
23,492 KB
testcase_13 AC 40 ms
13,700 KB
testcase_14 AC 47 ms
17,712 KB
testcase_15 AC 18 ms
10,072 KB
testcase_16 AC 61 ms
21,940 KB
testcase_17 AC 29 ms
9,344 KB
testcase_18 AC 144 ms
23,428 KB
testcase_19 AC 65 ms
16,232 KB
testcase_20 AC 30 ms
9,640 KB
testcase_21 AC 80 ms
27,316 KB
testcase_22 AC 77 ms
22,216 KB
testcase_23 AC 81 ms
12,760 KB
testcase_24 AC 8 ms
8,412 KB
testcase_25 AC 7 ms
8,208 KB
testcase_26 AC 4 ms
8,080 KB
testcase_27 AC 7 ms
8,232 KB
testcase_28 AC 8 ms
8,324 KB
testcase_29 AC 8 ms
8,496 KB
testcase_30 AC 7 ms
8,260 KB
testcase_31 AC 8 ms
8,284 KB
testcase_32 AC 5 ms
8,212 KB
testcase_33 AC 9 ms
8,344 KB
testcase_34 AC 8 ms
8,512 KB
testcase_35 AC 13 ms
8,532 KB
testcase_36 AC 11 ms
8,452 KB
testcase_37 AC 5 ms
8,136 KB
testcase_38 AC 8 ms
8,268 KB
testcase_39 AC 5 ms
8,144 KB
testcase_40 AC 6 ms
8,492 KB
testcase_41 AC 5 ms
8,132 KB
testcase_42 AC 8 ms
8,352 KB
testcase_43 AC 9 ms
8,460 KB
testcase_44 AC 6 ms
8,368 KB
testcase_45 AC 6 ms
9,404 KB
testcase_46 AC 8 ms
8,684 KB
testcase_47 AC 10 ms
9,172 KB
testcase_48 AC 13 ms
11,992 KB
testcase_49 AC 14 ms
9,884 KB
testcase_50 AC 31 ms
11,840 KB
testcase_51 AC 6 ms
8,200 KB
testcase_52 AC 30 ms
11,884 KB
testcase_53 AC 12 ms
9,792 KB
testcase_54 AC 5 ms
8,316 KB
testcase_55 AC 20 ms
11,400 KB
testcase_56 AC 6 ms
8,468 KB
testcase_57 AC 23 ms
10,152 KB
testcase_58 AC 13 ms
9,916 KB
testcase_59 AC 6 ms
8,420 KB
testcase_60 AC 6 ms
8,900 KB
testcase_61 AC 9 ms
8,596 KB
testcase_62 AC 14 ms
9,588 KB
testcase_63 AC 12 ms
8,888 KB
testcase_64 AC 162 ms
27,516 KB
testcase_65 AC 8 ms
8,632 KB
testcase_66 AC 77 ms
35,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<long long,pair<int,int>>
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; }
int n, s, t, k;
struct Edge {
	int to, cost;
	Edge(int _to, int _cost) :to(_to), cost(_cost) {}
};
vector<Edge>g[200005]; vector<vector<int>> data(3, vector<int>(4));
vector<long long>x;
void dikstra() {
	vector<vector<long long>> d(n, vector<long long>(k, LINF));
	vector<vector<pair<int, int>>> pre(n, vector<pair<int, int>>(k, { -1,-1 }));
	priority_queue<P, vector<P>, greater<P> > q;//小さいもの順
	q.push({ x[s], { s,0 } });
	d[s][0] = x[s];
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		long long cost = tmp.first;
		int pos = tmp.second.first;
		int count = tmp.second.second;
		if (cost > d[pos][count]) continue;
		for (Edge e : g[pos]) {
			long long ncost = cost + e.cost + x[e.to];
			int npos = e.to;
			int ncount = min(k - 1, count + 1);
			if (ncost < d[npos][ncount]) {
				pre[npos][ncount] = { pos,count };
				d[npos][ncount] = ncost;
				q.push({ d[npos][ncount], {npos,ncount} });
			}
		}
	}
	if (LINF == d[t][k - 1]) {
		cout << "Impossible" << endl;
	}
	else {
		cout << "Possible" << endl;
		cout << d[t][k - 1] << endl;
		vector<int>ans;
		ans.push_back(t);
		pair<int, int>p = pre[t][k - 1];
		while (true) {
			ans.push_back(p.first);
			p = pre[p.first][p.second];
			if (p.first == -1)break;
		}
		cout << ans.size() << endl;
		rrep(i, ans.size()) {
			cout << ans[i] + 1 << " ";
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> s >> t >> k;
	s--; t--;
	x.resize(n);
	rep(i, n)cin >> x[i];
	int m; cin >> m;
	rep(i, m) {
		int a, b, y; cin >> a >> b >> y;
		a--; b--;
		g[a].emplace_back(b, y);
	}
	dikstra();
	return 0;
}
0