Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
37572 Sakuzyh 【S】T2 C++ 通过 100 1385 MS 62716 KB 2599 2025-04-06 15:54:31

Tests(140/140):


// Author: Aquizahv #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 5, M = 3e5 + 5; int n, m, o, g[N]; vector<int> S, T; bool mark[N]; int head[N], pos; struct Edge { int u, v, w, nxt; } e[M]; ll ans[N]; inline int read() { bool f = 1; int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = !f; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return f ? x : -x; } inline void write(int x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) write(x / 10); putchar((x % 10) ^ 48); } void addEdge(int u, int v, int w) { e[++pos] = {u, v, w, head[u]}; head[u] = pos; } struct dij { int u; ll dis; bool operator<(const dij t) const { return dis > t.dis; } }; ll dis[N]; bool vis[N]; void dijkstra() { // for (auto u : T) // cout << u << ' '; // cout << endl; priority_queue<dij> q; memset(dis, 0x3f, sizeof(dis)); memset(vis, 0, sizeof(vis)); for (auto u : T) q.push({u, 0}), dis[u] = 0; while (!q.empty()) { int u = q.top().u; q.pop(); if (vis[u]) continue; vis[u] = true; for (int i = head[u]; i; i = e[i].nxt) if (dis[e[i].v] > dis[u] + e[i].w) { dis[e[i].v] = dis[u] + e[i].w; q.push({e[i].v, dis[e[i].v]}); } } for (int i = 1; i <= n; i++) if (dis[i] != 0) ans[i] = min(ans[i], dis[i]); // cout << dis[5] << endl; } int main() { n = read(), m = read(), o = read(); int u, v, w; for (int i = 1; i <= o; i++) S.push_back(read()); for (int i = 1; i <= m; i++) u = read(), v = read(), w = read(), addEdge(v, u, w); for (int i = 1; i <= n; i++) ans[i] = 1e18; T = S; dijkstra(); for (int k = 0; k < 18; k++) // for (auto v : S) { T.clear(); for (auto u : S) if ((u >> k) & 1) T.push_back(u); // for (auto u : S) // if (u != v) // T.push_back(u); dijkstra(); T.clear(); for (auto u : S) if (~(u >> k) & 1) T.push_back(u); dijkstra(); } for (int i = 1; i <= n; i++) printf("%lld%c", ans[i] * read(), " \n"[i == n]); return 0; }


测评信息: