Submission #1987878
Source Code Expand
# include <iostream> # include <algorithm> # include <vector> # include <string> # include <set> # include <map> # include <cmath> # include <iomanip> # include <functional> # include <tuple> # include <utility> # include <stack> # include <queue> # include <list> # include <bitset> # include <complex> # include <chrono> # include <random> # include <limits.h> # include <unordered_map> # include <unordered_set> # include <deque> # include <cstdio> # include <cstring> using namespace std; using LL = long long; using ULL = unsigned long long; constexpr long long MOD = 1000000000 + 7; constexpr long long INF = 1e17 - 10; const double PI = acos(-1); typedef pair<LL, LL> Pll; typedef pair<LL, pair<LL, LL>> Ppll; typedef pair<LL, LL> Vec2; typedef tuple<LL, LL, LL> Tll; typedef pair<LL, Tll> Ptll; #define rep(i,rept) for(LL i=0;i<rept;i++) #define Mfor(i,n) for(LL i=n-1;i>=0;i--) struct Edge { LL to, cost; }; vector<Edge>vec[1100000]; LL h[1100000], w, n, m, s, t, sum, ans = 0, d[1100000], mn; void DIUX(LL s) { for (int i = 0; i < 1100000; i++) d[i] = INF; d[s] = 0; priority_queue<Ppll, vector<Ppll>, greater<Ppll>> pq; pq.push(make_pair(d[s], Pll(s, 0))); // (cost,頂点番号) while (!pq.empty()) { Ppll pp; pp = pq.top(); LL cos = pp.first, vv = pp.second.first, nn = pp.second.second; pq.pop(); if (d[vv] < pp.first)continue; rep(i, vec[vv].size()) { if ((nn == vec[vv][i].cost||nn==0)&&d[vv] < d[vec[vv][i].to]) { d[vec[vv][i].to] = d[vv]; pq.push(make_pair(d[vec[vv][i].to], Pll(vec[vv][i].to, vec[vv][i].cost))); } if (d[vv] + 1 < d[vec[vv][i].to]) { d[vec[vv][i].to] = d[vv] + 1; pq.push(make_pair(d[vec[vv][i].to], Pll(vec[vv][i].to, 0))); } } } } int main() { cin >> n >> m; rep(i, m) { cin >> s >> t >> w; vec[s].push_back(Edge{ t,w }); vec[t].push_back(Edge{ s,w }); } DIUX(n); mn = d[1]; DIUX(1); mn = min(mn, d[n]); cout << (mn == INF ? -1 : mn+1) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Snuke's Subway Trip |
User | akusyounin |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2039 Byte |
Status | WA |
Exec Time | 290 ms |
Memory | 52328 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 | 14 ms | 37120 KB |
02.txt | AC | 145 ms | 45824 KB |
03.txt | WA | 277 ms | 49980 KB |
04.txt | AC | 244 ms | 49144 KB |
05.txt | WA | 257 ms | 50148 KB |
06.txt | WA | 106 ms | 41728 KB |
07.txt | WA | 156 ms | 43564 KB |
08.txt | WA | 290 ms | 50284 KB |
09.txt | WA | 165 ms | 43672 KB |
10.txt | WA | 161 ms | 43676 KB |
11.txt | AC | 207 ms | 51292 KB |
12.txt | AC | 132 ms | 45044 KB |
13.txt | AC | 168 ms | 47604 KB |
14.txt | AC | 218 ms | 51000 KB |
15.txt | AC | 174 ms | 49008 KB |
16.txt | AC | 213 ms | 51288 KB |
17.txt | AC | 205 ms | 51348 KB |
18.txt | AC | 147 ms | 46072 KB |
19.txt | AC | 208 ms | 50600 KB |
20.txt | AC | 215 ms | 51624 KB |
21.txt | AC | 225 ms | 51436 KB |
22.txt | AC | 204 ms | 50800 KB |
23.txt | WA | 228 ms | 52328 KB |
24.txt | AC | 198 ms | 50060 KB |
25.txt | AC | 123 ms | 45044 KB |
26.txt | AC | 155 ms | 46620 KB |
27.txt | AC | 207 ms | 50492 KB |
28.txt | AC | 197 ms | 50188 KB |
29.txt | AC | 202 ms | 51348 KB |
30.txt | AC | 197 ms | 50404 KB |
31.txt | AC | 145 ms | 46072 KB |
32.txt | AC | 197 ms | 51492 KB |
33.txt | AC | 206 ms | 51176 KB |
34.txt | AC | 200 ms | 51068 KB |
35.txt | AC | 123 ms | 45044 KB |
36.txt | AC | 159 ms | 46620 KB |
37.txt | AC | 206 ms | 51212 KB |
38.txt | AC | 203 ms | 50692 KB |
sample_01.txt | AC | 13 ms | 37120 KB |
sample_02.txt | AC | 13 ms | 37120 KB |
sample_03.txt | AC | 13 ms | 37120 KB |
w1.txt | WA | 226 ms | 48324 KB |
w10.txt | AC | 205 ms | 47360 KB |
w11.txt | AC | 125 ms | 43832 KB |
w12.txt | AC | 138 ms | 44928 KB |
w13.txt | WA | 156 ms | 45824 KB |
w14.txt | AC | 184 ms | 47360 KB |
w15.txt | AC | 123 ms | 43988 KB |
w16.txt | AC | 134 ms | 45056 KB |
w17.txt | AC | 150 ms | 45952 KB |
w18.txt | WA | 181 ms | 47360 KB |
w2.txt | WA | 226 ms | 50768 KB |
w3.txt | AC | 250 ms | 49604 KB |
w4.txt | AC | 234 ms | 49392 KB |
w5.txt | WA | 269 ms | 49392 KB |
w6.txt | AC | 242 ms | 49492 KB |
w7.txt | WA | 150 ms | 44124 KB |
w8.txt | WA | 161 ms | 44928 KB |
w9.txt | WA | 181 ms | 45824 KB |