This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19938 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
int n;
vector<pii> a;
vector<vector<int>> mp;
void init_(int _n) {
n = _n;
mp.assign(n + 1, vector<int>());
a.assign(n + 1, {-1, -1});
}
int solve() {
vector<int> dis(n + 1, INF);
priority_queue<pii> q;
dis[1] = 0, q.push({0, 1});
while(q.size()) {
pii p = q.top(); q.pop();
if(p.first != dis[p.second]) continue;
int cur = p.second;
for(auto i : mp[cur]) {
int v = dis[cur] + 1;
if(a[i].second < a[cur].second &&
(v - 1) % a[i].first == a[i].second) continue;
v += ((v % a[i].first) == a[i].second);
if(v < dis[i]) {
dis[i] = v;
q.push({v, i});
}
}
}
return dis[n];
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, m;
cin >> n >> m;
init_(n);
rep(i, 1, m) {
int a, b; cin >> a >> b;
mp[a].push_back(b);
mp[b].push_back(a);
}
int k; cin >> k;
rep(i, 1, k) {
int l; cin >> l;
rep(j, 0, l - 1) {
int x; cin >> x;
a[x] = {l, j};
}
}
cout << solve() << "\n";
return 0;
}
Compilation message (stderr)
watchmen.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
watchmen.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
watchmen.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |