Submission #2377928
Source Code Expand
#include <bits/stdc++.h> #define rep(n) for(int i=0;i<n;i++) #define repp(j, n) for(int j=0;j<n;j++) #define reppp(i, m, n) for(int i=m;i<n;i++) #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define debug(x) cerr << #x << ": " << x << endl; using namespace std; typedef long long ll; typedef pair<ll, ll> Pll; typedef pair<int, int> Pii; map<ll, ll> d; priority_queue< Pll, vector<Pll>, greater<Pll> > que; map<ll, vector<Pll> > edges; map<ll, bool> ok; ll n,m,p,r,c; void dijkstra(ll start){ d[start] = 0LL; que.push(Pll(0LL, start)); while(!que.empty()){ Pll v = que.top(); que.pop(); ok[v.second/(m+1LL)] = true; if(d.find(v.second) != d.end() && d[v.second] < v.first) continue; for(Pll e: edges[v.second]){ if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){ d[e.first] = d[v.second] + e.second; que.push(Pll(d[e.first], e.first)); } } } } int main() { std::ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(m){ cin >> p >> r >> c; p--; r--; if(p == 0) ok[r] = true; if(r == 0) ok[p] = true; edges[p*(m+1LL)+c].emplace_back(r*(m+1LL)+c, 0LL); edges[r*(m+1LL)+c].emplace_back(p*(m+1LL)+c, 0LL); edges[p*(m+1LL)].emplace_back(p*(m+1LL)+c, 0LL); edges[p*(m+1LL)+c].emplace_back(p*(m+1LL), 1LL); edges[r*(m+1LL)].emplace_back(r*(m+1LL)+c, 0LL); edges[r*(m+1LL)+c].emplace_back(r*(m+1LL), 1LL); } dijkstra(0LL); cout << (ok[n-1]?d[(n-1LL)*(m+1LL)]:-1) << endl; }
Submission Info
Submission Time | |
---|---|
Task | E - Snuke's Subway Trip |
User | Noimin |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1694 Byte |
Status | WA |
Exec Time | 1758 ms |
Memory | 106484 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 600 | ||||
Status | AC |
|
Set Name | Test Cases |
---|---|
Sample | |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, sample_01.txt, sample_02.txt, sample_03.txt, w1.txt, w10.txt, w11.txt, w12.txt, w13.txt, w14.txt, w15.txt, w16.txt, w17.txt, w18.txt, w2.txt, w3.txt, w4.txt, w5.txt, w6.txt, w7.txt, w8.txt, w9.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 2 ms | 384 KB |
02.txt | AC | 880 ms | 43384 KB |
03.txt | AC | 1758 ms | 106484 KB |
04.txt | AC | 585 ms | 68096 KB |
05.txt | AC | 1447 ms | 87792 KB |
06.txt | AC | 704 ms | 60544 KB |
07.txt | AC | 798 ms | 62460 KB |
08.txt | AC | 1623 ms | 105844 KB |
09.txt | AC | 906 ms | 67580 KB |
10.txt | AC | 878 ms | 67580 KB |
11.txt | AC | 814 ms | 66536 KB |
12.txt | AC | 166 ms | 24668 KB |
13.txt | AC | 548 ms | 39392 KB |
14.txt | AC | 835 ms | 65644 KB |
15.txt | AC | 694 ms | 55408 KB |
16.txt | AC | 746 ms | 61160 KB |
17.txt | AC | 871 ms | 67308 KB |
18.txt | AC | 351 ms | 29676 KB |
19.txt | AC | 760 ms | 61904 KB |
20.txt | AC | 940 ms | 70508 KB |
21.txt | AC | 1393 ms | 101228 KB |
22.txt | AC | 1010 ms | 74092 KB |
23.txt | AC | 1136 ms | 84460 KB |
24.txt | AC | 845 ms | 69740 KB |
25.txt | AC | 161 ms | 23536 KB |
26.txt | AC | 479 ms | 38640 KB |
27.txt | AC | 896 ms | 72940 KB |
28.txt | AC | 833 ms | 69996 KB |
29.txt | AC | 896 ms | 72428 KB |
30.txt | AC | 819 ms | 67180 KB |
31.txt | AC | 492 ms | 38768 KB |
32.txt | AC | 768 ms | 60908 KB |
33.txt | AC | 914 ms | 72684 KB |
34.txt | AC | 643 ms | 56180 KB |
35.txt | AC | 141 ms | 24048 KB |
36.txt | AC | 350 ms | 31988 KB |
37.txt | AC | 729 ms | 59120 KB |
38.txt | AC | 644 ms | 56688 KB |
sample_01.txt | AC | 1 ms | 256 KB |
sample_02.txt | AC | 1 ms | 256 KB |
sample_03.txt | AC | 1 ms | 256 KB |
w1.txt | AC | 780 ms | 60920 KB |
w10.txt | WA | 1365 ms | 89216 KB |
w11.txt | AC | 199 ms | 23556 KB |
w12.txt | AC | 378 ms | 30336 KB |
w13.txt | AC | 748 ms | 50944 KB |
w14.txt | AC | 884 ms | 74880 KB |
w15.txt | AC | 103 ms | 23768 KB |
w16.txt | AC | 175 ms | 24832 KB |
w17.txt | AC | 287 ms | 28160 KB |
w18.txt | AC | 639 ms | 43264 KB |
w2.txt | AC | 726 ms | 60920 KB |
w3.txt | AC | 1043 ms | 75584 KB |
w4.txt | AC | 817 ms | 62572 KB |
w5.txt | AC | 1531 ms | 106096 KB |
w6.txt | AC | 1188 ms | 88304 KB |
w7.txt | WA | 1232 ms | 81656 KB |
w8.txt | WA | 1241 ms | 82928 KB |
w9.txt | WA | 1226 ms | 83968 KB |