結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー tkmst201
提出日時 2021-07-11 10:47:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 249 ms / 3,000 ms
コード長 1,808 bytes
コンパイル時間 2,920 ms
コンパイル使用メモリ 215,872 KB
最終ジャッジ日時 2025-01-23 00:35:27
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 67
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         REP(i, N) scanf("%d", &X[i]);
      |                   ~~~~~^~~~~~~~~~~~~
main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |                 scanf("%d %d %d", &a, &b, &y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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