Submission #1987910
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, 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; if (cos + 1 < d[vv]) { d[vv] = cos + 1; pq.push(make_pair(d[vv], Pll(vv, 0))); } rep(i, vec[vv].size()) { if ((nn == vec[vv][i].cost || nn == 0) && d[vv] < d[vec[vv][i].to]) { pq.push(make_pair(cos, Pll(vec[vv][i].to, vec[vv][i].cost))); } } } } 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) << 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 | 1940 Byte |
Status | RE |
Exec Time | 3179 ms |
Memory | 1619404 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 | 34688 KB |
02.txt | AC | 151 ms | 43520 KB |
03.txt | AC | 344 ms | 47620 KB |
04.txt | AC | 267 ms | 46712 KB |
05.txt | AC | 318 ms | 47800 KB |
06.txt | AC | 113 ms | 39296 KB |
07.txt | AC | 182 ms | 41204 KB |
08.txt | AC | 346 ms | 47876 KB |
09.txt | AC | 191 ms | 41244 KB |
10.txt | AC | 186 ms | 41248 KB |
11.txt | AC | 280 ms | 52348 KB |
12.txt | TLE | 3178 ms | 1616588 KB |
13.txt | AC | 382 ms | 67160 KB |
14.txt | AC | 276 ms | 48824 KB |
15.txt | AC | 250 ms | 56680 KB |
16.txt | AC | 270 ms | 48896 KB |
17.txt | AC | 265 ms | 51180 KB |
18.txt | TLE | 3179 ms | 1617100 KB |
19.txt | AC | 324 ms | 61548 KB |
20.txt | AC | 286 ms | 53756 KB |
21.txt | AC | 1120 ms | 49028 KB |
22.txt | AC | 287 ms | 54480 KB |
23.txt | AC | 307 ms | 49836 KB |
24.txt | TLE | 3171 ms | 1489996 KB |
25.txt | TLE | 3158 ms | 436948 KB |
26.txt | AC | 393 ms | 66920 KB |
27.txt | TLE | 3157 ms | 240860 KB |
28.txt | TLE | 3175 ms | 1617100 KB |
29.txt | TLE | 3159 ms | 830720 KB |
30.txt | TLE | 3174 ms | 1616844 KB |
31.txt | AC | 380 ms | 67484 KB |
32.txt | TLE | 3174 ms | 1619404 KB |
33.txt | TLE | 3158 ms | 437104 KB |
34.txt | AC | 299 ms | 53528 KB |
35.txt | RE | 2673 ms | 1617740 KB |
36.txt | AC | 855 ms | 92512 KB |
37.txt | AC | 309 ms | 54032 KB |
38.txt | AC | 292 ms | 53964 KB |
sample_01.txt | AC | 13 ms | 34560 KB |
sample_02.txt | AC | 13 ms | 34560 KB |
sample_03.txt | AC | 13 ms | 34560 KB |
w1.txt | TLE | 3159 ms | 830252 KB |
w10.txt | AC | 229 ms | 44928 KB |
w11.txt | TLE | 3157 ms | 141212 KB |
w12.txt | TLE | 3157 ms | 142816 KB |
w13.txt | WA | 211 ms | 43392 KB |
w14.txt | AC | 200 ms | 44928 KB |
w15.txt | TLE | 3158 ms | 435504 KB |
w16.txt | RE | 2490 ms | 1616528 KB |
w17.txt | TLE | 3158 ms | 338532 KB |
w18.txt | WA | 243 ms | 45144 KB |
w2.txt | TLE | 3174 ms | 1619244 KB |
w3.txt | AC | 333 ms | 49820 KB |
w4.txt | AC | 411 ms | 54788 KB |
w5.txt | AC | 364 ms | 50116 KB |
w6.txt | AC | 345 ms | 49648 KB |
w7.txt | TLE | 3157 ms | 41948 KB |
w8.txt | AC | 714 ms | 42496 KB |
w9.txt | AC | 308 ms | 43392 KB |