結果
| 問題 |
No.3326 岩井星人の帰星
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-11-07 12:19:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 146 ms / 2,000 ms |
| コード長 | 1,576 bytes |
| コンパイル時間 | 671 ms |
| コンパイル使用メモリ | 68,248 KB |
| 実行使用メモリ | 19,208 KB |
| 最終ジャッジ日時 | 2025-11-07 12:19:32 |
| 合計ジャッジ時間 | 6,760 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 59 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:39:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d", &l);
| ~~~~~^~~~~~~~~~
main.cpp:46:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | for (int i = 0; i < l; i++) scanf("%d%d", js + i, ks + i), js[i]--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3326.cc: No.3326 蟯ゥ莠墓弌莠コ縺ョ蟶ー譏・- yukicoder
*/
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
using vi = vector<int>;
using qi = queue<int>;
using pii = pair<int,int>;
/* global variables */
vi nbrs[MAX_N];
int js[MAX_N], ks[MAX_N];
int bs[MAX_N], ds[MAX_N];
/* subroutines */
/* main */
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
u--, v--;
nbrs[u].push_back(v);
nbrs[v].push_back(u);
}
int l;
scanf("%d", &l);
for (int i = 0; i < l; i++) scanf("%d%d", js + i, ks + i), js[i]--;
priority_queue<pii> pq;
for (int i = 0; i < l; i++) {
bs[js[i]] = ks[i] + 1;
if (ks[i] > 0) pq.push({ks[i] + 1, js[i]});
}
while (! pq.empty()) {
auto [ub, u] = pq.top(); pq.pop();
if (ub != bs[u]) continue;
int vb = ub - 1;
for (auto v: nbrs[u])
if (bs[v] < vb) {
bs[v] = vb;
if (vb > 1) pq.push({vb, v});
}
}
if (bs[0] > 0) { puts("No"); return 0; }
//for (int i = 0; i < n; i++) printf(" %d", bs[i]); putchar('\n');
fill(ds, ds + n, -1);
ds[0] = 0;
qi q;
q.push(0);
while (! q.empty()) {
int u = q.front(); q.pop();
if (u == n - 1) break;
for (auto v: nbrs[u])
if (ds[v] < 0 && bs[v] == 0)
ds[v] = ds[u] + 1, q.push(v);
}
if (ds[n - 1] >= 0) printf("Yes\n%d\n", ds[n - 1]);
else puts("No");
return 0;
}
tnakao0123