Submission #35557346
Source Code Expand
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <cmath> #include <queue> using namespace std; #define mp make_pair #define pb push_back #define ll long long const int maxN = 100011; int n, m, k, x, y; int a[maxN], b[maxN]; int best[maxN]; vector<int> adj[maxN]; priority_queue< pair<int, int> > heap; int main() { cin >> n >> m >> k; for (int i = 0; i < m; i++) { cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } for (int i = 1; i <= n; i++) { cin >> a[i]; best[i] = k; } for (int i = 1; i <= k; i++) cin >> b[i]; b[k + 1] = -1; best[1] = (a[1] == b[1]) ? 1 : 0; heap.push(mp(-best[1], 1)); while (!heap.empty()) { const auto [val, node] = heap.top(); heap.pop(); int curr = -val; if (curr != best[node]) continue; for (auto to: adj[node]) { int new_best = best[node] + (a[to] == b[curr + 1] ? 1 : 0); if (new_best < best[to]) { best[to] = new_best; heap.push(mp(-new_best, to)); } } } if (best[n] == k) cout << "Yes\n"; else cout << "No\n"; for (int i = 1; i <= n; i++) cerr << best[i] << ' '; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Path and Subsequence |
User | atatomir |
Language | C++ (Clang 10.0.0) |
Score | 500 |
Code Size | 1277 Byte |
Status | AC |
Exec Time | 618 ms |
Memory | 10552 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-yes-001.txt, 01-yes-002.txt, 01-yes-003.txt, 01-yes-004.txt, 01-yes-005.txt, 01-yes-006.txt, 01-yes-007.txt, 01-yes-008.txt, 01-yes-009.txt, 01-yes-010.txt, 01-yes-011.txt, 01-yes-012.txt, 01-yes-013.txt, 01-yes-014.txt, 01-yes-015.txt, 01-yes-016.txt, 01-yes-017.txt, 01-yes-018.txt, 01-yes-019.txt, 01-yes-020.txt, 01-yes-021.txt, 01-yes-022.txt, 01-yes-023.txt, 01-yes-024.txt, 01-yes-025.txt, 02-no-001.txt, 02-no-002.txt, 02-no-003.txt, 02-no-004.txt, 02-no-005.txt, 02-no-006.txt, 02-no-007.txt, 02-no-008.txt, 02-no-009.txt, 02-no-010.txt, 02-no-011.txt, 02-no-012.txt, 02-no-013.txt, 02-no-014.txt, 02-no-015.txt, 02-no-016.txt, 02-no-017.txt, 02-no-018.txt, 02-no-019.txt, 02-no-020.txt, 02-no-021.txt, 02-no-022.txt, 02-no-023.txt, 02-no-024.txt, 02-no-025.txt, 03-test-001.txt, 03-test-002.txt, 03-test-003.txt, 03-test-004.txt, 03-test-005.txt, 03-test-006.txt, 03-test-007.txt, 03-test-008.txt, 03-test-009.txt, 04-strong-001.txt, 04-strong-002.txt, 04-strong-003.txt, 04-strong-004.txt, 04-strong-005.txt, 04-strong-006.txt, 04-strong-007.txt, 04-strong-008.txt, 04-strong-009.txt, 04-strong-010.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00-sample-001.txt | AC | 10 ms | 5396 KiB |
00-sample-002.txt | AC | 4 ms | 5456 KiB |
00-sample-003.txt | AC | 5 ms | 5344 KiB |
01-yes-001.txt | AC | 591 ms | 10336 KiB |
01-yes-002.txt | AC | 594 ms | 10352 KiB |
01-yes-003.txt | AC | 597 ms | 10400 KiB |
01-yes-004.txt | AC | 575 ms | 10492 KiB |
01-yes-005.txt | AC | 593 ms | 10368 KiB |
01-yes-006.txt | AC | 597 ms | 10464 KiB |
01-yes-007.txt | AC | 597 ms | 10440 KiB |
01-yes-008.txt | AC | 601 ms | 10424 KiB |
01-yes-009.txt | AC | 602 ms | 10476 KiB |
01-yes-010.txt | AC | 588 ms | 10496 KiB |
01-yes-011.txt | AC | 601 ms | 10388 KiB |
01-yes-012.txt | AC | 596 ms | 10424 KiB |
01-yes-013.txt | AC | 606 ms | 10416 KiB |
01-yes-014.txt | AC | 591 ms | 10496 KiB |
01-yes-015.txt | AC | 601 ms | 10516 KiB |
01-yes-016.txt | AC | 612 ms | 10472 KiB |
01-yes-017.txt | AC | 618 ms | 10448 KiB |
01-yes-018.txt | AC | 613 ms | 10420 KiB |
01-yes-019.txt | AC | 613 ms | 10420 KiB |
01-yes-020.txt | AC | 613 ms | 10552 KiB |
01-yes-021.txt | AC | 597 ms | 10476 KiB |
01-yes-022.txt | AC | 604 ms | 10432 KiB |
01-yes-023.txt | AC | 591 ms | 10472 KiB |
01-yes-024.txt | AC | 584 ms | 10444 KiB |
01-yes-025.txt | AC | 578 ms | 10340 KiB |
02-no-001.txt | AC | 594 ms | 10252 KiB |
02-no-002.txt | AC | 583 ms | 10224 KiB |
02-no-003.txt | AC | 595 ms | 10368 KiB |
02-no-004.txt | AC | 582 ms | 10396 KiB |
02-no-005.txt | AC | 602 ms | 10264 KiB |
02-no-006.txt | AC | 602 ms | 10520 KiB |
02-no-007.txt | AC | 603 ms | 10520 KiB |
02-no-008.txt | AC | 599 ms | 10520 KiB |
02-no-009.txt | AC | 606 ms | 10520 KiB |
02-no-010.txt | AC | 583 ms | 10440 KiB |
02-no-011.txt | AC | 605 ms | 10384 KiB |
02-no-012.txt | AC | 598 ms | 10416 KiB |
02-no-013.txt | AC | 611 ms | 10484 KiB |
02-no-014.txt | AC | 593 ms | 10440 KiB |
02-no-015.txt | AC | 605 ms | 10512 KiB |
02-no-016.txt | AC | 617 ms | 10528 KiB |
02-no-017.txt | AC | 614 ms | 10552 KiB |
02-no-018.txt | AC | 612 ms | 10508 KiB |
02-no-019.txt | AC | 613 ms | 10540 KiB |
02-no-020.txt | AC | 613 ms | 10524 KiB |
02-no-021.txt | AC | 587 ms | 10260 KiB |
02-no-022.txt | AC | 579 ms | 10352 KiB |
02-no-023.txt | AC | 593 ms | 10376 KiB |
02-no-024.txt | AC | 577 ms | 10200 KiB |
02-no-025.txt | AC | 590 ms | 10432 KiB |
03-test-001.txt | AC | 8 ms | 5344 KiB |
03-test-002.txt | AC | 5 ms | 5420 KiB |
03-test-003.txt | AC | 484 ms | 9240 KiB |
03-test-004.txt | AC | 502 ms | 9480 KiB |
03-test-005.txt | AC | 584 ms | 9452 KiB |
03-test-006.txt | AC | 585 ms | 9348 KiB |
03-test-007.txt | AC | 565 ms | 9304 KiB |
03-test-008.txt | AC | 504 ms | 9760 KiB |
03-test-009.txt | AC | 509 ms | 9756 KiB |
04-strong-001.txt | AC | 512 ms | 9648 KiB |
04-strong-002.txt | AC | 516 ms | 9644 KiB |
04-strong-003.txt | AC | 509 ms | 9624 KiB |
04-strong-004.txt | AC | 509 ms | 9508 KiB |
04-strong-005.txt | AC | 509 ms | 9548 KiB |
04-strong-006.txt | AC | 595 ms | 9288 KiB |
04-strong-007.txt | AC | 503 ms | 9760 KiB |
04-strong-008.txt | AC | 495 ms | 9384 KiB |
04-strong-009.txt | AC | 502 ms | 9544 KiB |
04-strong-010.txt | AC | 498 ms | 9316 KiB |