結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー kwm_t
提出日時 2021-06-17 18:09:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 183 ms / 3,000 ms
コード長 2,483 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 182,516 KB
実行使用メモリ 35,968 KB
最終ジャッジ日時 2025-01-03 03:18:48
合計ジャッジ時間 15,789 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0