Task: | Peli |
Sender: | Kemm1706 |
Submission time: | 2024-01-20 14:50:57 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 42 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 42 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2 | details |
#2 | ACCEPTED | 0.00 s | 1, 2 | details |
#3 | TIME LIMIT EXCEEDED | -- | 2 | details |
#4 | ACCEPTED | 0.00 s | 1, 2 | details |
#5 | ACCEPTED | 0.00 s | 1, 2 | details |
#6 | TIME LIMIT EXCEEDED | -- | 2 | details |
#7 | TIME LIMIT EXCEEDED | -- | 2 | details |
#8 | ACCEPTED | 0.00 s | 1, 2 | details |
#9 | TIME LIMIT EXCEEDED | -- | 2 | details |
#10 | TIME LIMIT EXCEEDED | -- | 2 | details |
Compiler report
input/code.cpp: In function 'pl bfs(const vvl&, ll, ll, ll, ll)': input/code.cpp:28:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' 28 | auto [u, v] = q.front(); | ^ input/code.cpp:39:19: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else] 39 | if(x == b) | ^ input/code.cpp:21:8: warning: variable 'ans' set but not used [-Wunused-but-set-variable] 21 | pl ans = {-1, -1}, pre; | ^~~
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector <ll> vl; typedef vector <vl> vvl; typedef pair <ll, ll> pl; typedef vector <pl> vpl; typedef vector <bool> vb; const ll inf = 1e18; const ll mod = 1e9 + 7; const ll nmax = 1e6; #define fi first #define se second #define mp make_pair #define pb push_back pl bfs(const vvl &g, ll a, ll b, ll k, ll n) { pl ans = {-1, -1}, pre; queue <pair <ll, pl>> q; vpl val(n + 1, {-1, -1}); val[a] = {0, -1}; q.push({a, {0, -1}}); while(!q.empty()) { auto [u, v] = q.front(); q.pop(); for(auto x : g[u]) { if(val[x].fi == -1 || val[x].se == -1) { pre = val[x]; if(val[x].fi == -1 && v.se != -1) val[x].fi = v.se + 1; if(val[x].se == -1 && v.fi != -1) val[x].se = v.fi + 1; if(x == b) if(k % 2 == 0) if(val[x].fi != -1) return val[x]; else; else if(val[x].se != -1) return val[x]; if(pre != val[x]) q.push({x, val[x]}); } } } /*for(auto x : val) cerr << x.fi << "," << x.se << " ";*/ return val[b]; } /*4 5 6 1 2 2 3 1 3 2 4 3 4 1 2 2 1 4 1 1 4 5 2 2 1 2 2 2 3 4 8*/ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m, q, i, a, b, k; pl ans; cin >> n >> m >> q; vvl g(n + 1); vpl minn(n + 1, {inf, inf}); for(i = 0; i < m; i++) { cin >> a >> b; g[a].pb(b); g[b].pb(a); } while(q--) { cin >> a >> b >> k; ans = bfs(g, a, b, k, n); //cout << ans.fi << " " << ans.se << "\n"; if(k % 2 == 0) if(ans.fi != -1 && ans.fi <= k) cout << "YES\n"; else cout << "NO\n"; else if(ans.se != -1 && ans.se <= k) cout << "YES\n"; else cout << "NO\n"; } return 0; }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
2 1 100 1 2 1 1 0 1 2 0 2 1 0 ... |
correct output |
---|
YES NO NO YES NO ... |
user output |
---|
YES NO NO YES NO ... Truncated |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
50 49 100 33 34 7 8 49 50 47 48 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... Truncated |
Test 3
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
2500 2499 100000 821 822 2351 2352 752 753 832 833 ... |
correct output |
---|
NO YES YES NO NO ... |
user output |
---|
(empty) |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
12 12 100 9 10 2 3 1 12 1 2 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... Truncated |
Test 5
Group: 1, 2
Verdict: ACCEPTED
input |
---|
11 11 100 10 11 7 8 1 2 5 6 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... Truncated |
Test 6
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
2500 2500 100000 1936 1937 1884 1885 751 752 831 832 ... |
correct output |
---|
NO YES YES NO NO ... |
user output |
---|
(empty) |
Test 7
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
2499 2499 100000 821 822 2351 2352 752 753 832 833 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
(empty) |
Test 8
Group: 1, 2
Verdict: ACCEPTED
input |
---|
50 99 100 40 47 34 50 44 47 15 16 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... Truncated |
Test 9
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
2500 4999 100000 1191 2361 251 399 1026 2300 82 1655 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
(empty) |
Test 10
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
2500 4999 100000 2023 2218 23 51 1020 1272 11 114 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
(empty) |