結果

問題 No.3326 岩井星人の帰星
コンテスト
ユーザー ルビサファせだい
提出日時 2025-11-03 21:57:45
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,746 bytes
コンパイル時間 4,578 ms
コンパイル使用メモリ 291,316 KB
実行使用メモリ 22,108 KB
最終ジャッジ日時 2025-11-03 21:57:58
合計ジャッジ時間 10,040 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

// #include <atcoder/fenwicktree.hpp>
// #include <atcoder/segtree.hpp>
// #include <atcoder/modint.hpp>
// #include <atcoder/dsu.hpp>
// #include <atcoder/lazysegtree.hpp>

// using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
ll ll_min = numeric_limits<ll>::min();
ll ll_max = numeric_limits<ll>::max();
ll ALPHABET_N = 26;
// using mint = modint998244353;
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(a) a.begin(), a.end()

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> G(n);
	rep(i, m)
	{
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	max_heap<pair<ll, ll>> pq;
	vector<ll> bestK(n, -1);
	ll l;
	cin >> l;
	rep(_, l)
	{
		ll j, k;
		cin >> j >> k;
		j--;
		bestK[j] = k;
		pq.push({k, j});
	}
	while (!pq.empty())
	{
		auto [k, v] = pq.top();
		pq.pop();
		if (k < bestK[v])
			continue;
		for (auto nex : G[v])
		{
			if (bestK[nex] < (k - 1))
			{
				bestK[nex] = k - 1;
				pq.push({k - 1, nex});
			}
		}
	}
	vector<ll> dists(n, ll_max);
	if (bestK[0] == -1)
	{
		dists[0] = 0;
		queue<ll> q;
		q.push(0);
		while (!q.empty())
		{
			ll v = q.front();
			q.pop();
			ll nd = dists[v] + 1;
			for (auto nex : G[v])
			{
				if (nd < dists[nex])
				{
					dists[nex] = nd;
					q.push(nex);
				}
			}
		}
	}
	if (dists[n - 1] == ll_max)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
		cout << dists[n - 1] << endl;
	}
	return 0;
}
0