diff --git a/S2OJ/1498/1498.cpp b/S2OJ/1498/1498.cpp new file mode 100644 index 00000000..65476375 --- /dev/null +++ b/S2OJ/1498/1498.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1000005; + +int n, m, id[N], last[N], dist[N]; +bool vis[N]; +std::set cs; +std::vector> c[N], g[N]; + +void bfs() { + memset(dist, 0x3f, sizeof(dist)); + + std::deque q; + + dist[1] = 0; + q.emplace_back(1); + + while (!q.empty()) { + int u = q.front(); + q.pop_front(); + + if (vis[u]) continue; + vis[u] = true; + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (dist[v] > dist[u] + w) { + dist[v] = dist[u] + w; + + if (w) q.emplace_back(v); + else q.emplace_front(v); + } + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1, u, v, c; i <= m; i++) { + cin >> u >> v >> c; + + ::c[c].emplace_back(u, v); + cs.insert(c); + } + + int cnt = n; + for (int x : cs) { + for (auto e : c[x]) { + int u = e.first, + v = e.second; + + if (last[u] != x) { + last[u] = x; + id[u] = ++cnt; + g[u].emplace_back(id[u], 1); + g[id[u]].emplace_back(u, 0); + } + + if (last[v] != x) { + last[v] = x; + id[v] = ++cnt; + g[v].emplace_back(id[v], 1); + g[id[v]].emplace_back(v, 0); + } + + g[id[u]].emplace_back(id[v], 0); + g[id[v]].emplace_back(id[u], 0); + } + } + + bfs(); + + cout << (dist[n] == 0x3f3f3f3f ? -1 : dist[n]) << endl; + + return 0; +} diff --git a/S2OJ/1498/data/data1.in b/S2OJ/1498/data/data1.in new file mode 100644 index 00000000..a1c5dbaf --- /dev/null +++ b/S2OJ/1498/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9077d613e50c61ba786bab445e03a7511558b936299adcd343597aee7f94ec5 +size 2785942 diff --git a/S2OJ/1498/data/data1.out b/S2OJ/1498/data/data1.out new file mode 100644 index 00000000..af3eb40c --- /dev/null +++ b/S2OJ/1498/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48430c59951df1d835a871172779c933db36c45bf79c702fc7d1b77c5e47460e +size 4 diff --git a/S2OJ/1498/data/data10.in b/S2OJ/1498/data/data10.in new file mode 100644 index 00000000..4cff4503 --- /dev/null +++ b/S2OJ/1498/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1dbe91a537e114d1e1de90befe3e7785d9139582e5f066e2725b7720388471e +size 2766518 diff --git a/S2OJ/1498/data/data10.out b/S2OJ/1498/data/data10.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/S2OJ/1498/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/S2OJ/1498/data/data2.in b/S2OJ/1498/data/data2.in new file mode 100644 index 00000000..f5f6395b --- /dev/null +++ b/S2OJ/1498/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed8283dc64e900ef6e0f89d028c50a1f23c626060fdaa180d1ea2eb88300497a +size 2578443 diff --git a/S2OJ/1498/data/data2.out b/S2OJ/1498/data/data2.out new file mode 100644 index 00000000..82a2c368 --- /dev/null +++ b/S2OJ/1498/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a4c3fab369b31128edafea3f0f58e62fe72bcb6f9304f5d4fe2760aba0246de +size 4 diff --git a/S2OJ/1498/data/data3.in b/S2OJ/1498/data/data3.in new file mode 100644 index 00000000..00e81080 --- /dev/null +++ b/S2OJ/1498/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc384524f71447767a9b8ff5ee61a89c3d8a360af3f2c9b2b88d789bc6673b08 +size 3156947 diff --git a/S2OJ/1498/data/data3.out b/S2OJ/1498/data/data3.out new file mode 100644 index 00000000..794b53ff --- /dev/null +++ b/S2OJ/1498/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:26d2d36bb37bb0007a7da09107bff86d2f96837c27c3b684cce7c7c16e621bb2 +size 5 diff --git a/S2OJ/1498/data/data4.in b/S2OJ/1498/data/data4.in new file mode 100644 index 00000000..c8fbcda6 --- /dev/null +++ b/S2OJ/1498/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46e1f8eafee2903179314b38267f87e1049199a774ce4781a89e0c9a6269a3cb +size 2362181 diff --git a/S2OJ/1498/data/data4.out b/S2OJ/1498/data/data4.out new file mode 100644 index 00000000..d9b42081 --- /dev/null +++ b/S2OJ/1498/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a6082659f35a2809c92fdf5707625c448b72cdf0a4e0c55a68c722bc8136947 +size 4 diff --git a/S2OJ/1498/data/data5.in b/S2OJ/1498/data/data5.in new file mode 100644 index 00000000..cf94b3f1 --- /dev/null +++ b/S2OJ/1498/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6751b94fab83189e3a528da15d6397680ef5dbc744146dbc1f5cf45ca43dd764 +size 2632618 diff --git a/S2OJ/1498/data/data5.out b/S2OJ/1498/data/data5.out new file mode 100644 index 00000000..d595cdb8 --- /dev/null +++ b/S2OJ/1498/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7de1555df0c2700329e815b93b32c571c3ea54dc967b89e81ab73b9972b72d1d +size 2 diff --git a/S2OJ/1498/data/data6.in b/S2OJ/1498/data/data6.in new file mode 100644 index 00000000..fbf63ec9 --- /dev/null +++ b/S2OJ/1498/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe74cae788052ae094b0550c4c99cf946b313e2c569a8bab3100f2b6ef8027d5 +size 3733381 diff --git a/S2OJ/1498/data/data6.out b/S2OJ/1498/data/data6.out new file mode 100644 index 00000000..d790bd49 --- /dev/null +++ b/S2OJ/1498/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e6d31a5983a91251bfae5aefa1c0a19d8ba3cf601d0e8a706b4cfa9661a6b8a +size 2 diff --git a/S2OJ/1498/data/data7.in b/S2OJ/1498/data/data7.in new file mode 100644 index 00000000..e9233298 --- /dev/null +++ b/S2OJ/1498/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6a05d7d781023d29917287d4dbe31a5fbb1cf8abc499a70026f992e5fed0657 +size 29406 diff --git a/S2OJ/1498/data/data7.out b/S2OJ/1498/data/data7.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/S2OJ/1498/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/S2OJ/1498/data/data8.in b/S2OJ/1498/data/data8.in new file mode 100644 index 00000000..26827688 --- /dev/null +++ b/S2OJ/1498/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7b2b9c82dbe2f8c97a2e88755775cd034728f4031dc0e28a58184ef4ea5807d +size 29468 diff --git a/S2OJ/1498/data/data8.out b/S2OJ/1498/data/data8.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/S2OJ/1498/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2 diff --git a/S2OJ/1498/data/data9.in b/S2OJ/1498/data/data9.in new file mode 100644 index 00000000..729b10e6 --- /dev/null +++ b/S2OJ/1498/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15ac9eb294804b2e94b8659b3531015b6895de2bb14ed514b0686ddcd6184abf +size 29210 diff --git a/S2OJ/1498/data/data9.out b/S2OJ/1498/data/data9.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/S2OJ/1498/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/S2OJ/1498/data/problem.conf b/S2OJ/1498/data/problem.conf new file mode 100644 index 00000000..4123f747 --- /dev/null +++ b/S2OJ/1498/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea854f4e7fc39bb22aeb2188ace2efdd3dee3e986edbcd7e2d0d7404b9941574 +size 177