結果
| 問題 | No.2565 はじめてのおつかい |
| コンテスト | |
| ユーザー |
Solalyth
|
| 提出日時 | 2026-06-19 12:12:28 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 911 bytes |
| 記録 | |
| コンパイル時間 | 3,625 ms |
| コンパイル使用メモリ | 339,376 KB |
| 実行使用メモリ | 12,032 KB |
| 最終ジャッジ日時 | 2026-06-19 12:12:35 |
| 合計ジャッジ時間 | 5,942 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 31 WA * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i, a, b) for(LL i=(a); i<(b); i++)
template <typename T> bool chmin(T& a, const T& b) { return a>b ? a=b,1 : 0; }
int main() {
int N, M; cin >> N >> M;
vector<int> E[1<<17];
rep(_, 0, M) {
int u, v; cin >> u >> v;
E[u].push_back(v);
E[v].push_back(u);
}
const int inf = 1<<27;
deque<pair<int, int>> que = {{0, 0}};
int d[4][1<<17]; rep(i, 0, 4) rep(j, 0, 1<<17) { d[i][j] = inf; }
while(!que.empty()) {
auto [k, i] = que.front(); que.pop_front();
for(auto j: E[i]) {
int xk = k;
if (j == N-2) { xk |= 1; }
if (j == N-1) { xk |= 2; }
if (chmin(d[xk][j], d[k][i]+1)) {
que.push_back(make_pair(xk, j));
}
}
}
if (d[3][0] == inf) { d[3][0] = -1; }
cout << d[3][0];
}
Solalyth