1 条题解
-
0
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; const int N = 310, inf = 0x3f3f3f3f; vector<PII> G[N]; int B[N], P[N], R[N], d[N]; char C[N]; bool v[N]; char Color(int x, int t) { t = t % (B[x] + P[x]); if (t < R[x]) return C[x]; if (C[x] == 'B') return (t < R[x] + P[x]) ? 'P' : 'B'; else return (t < R[x] + B[x]) ? 'B' : 'P'; } int cal(int x, int y) { for (int i = d[x]; i <= d[x] + B[x] + P[x] + B[y] + P[y]; i++) if (Color(x, i) == Color(y, i)) return i; return inf; } int main() { int st, ed, n, m; scanf("%d%d%d%d\n", &st, &ed, &n, &m); for (int i = 1; i <= n; i++) scanf("%c%d%d%d\n", &C[i], &R[i], &B[i], &P[i]); for (int i = 1, x, y, w; i <= m; i++) { scanf("%d%d%d", &x, &y, &w); G[x].push_back({y, w}); G[y].push_back({x, w}); } memset(d, 0x3f, sizeof(d)); d[st] = 0; memset(v, 0, sizeof(v)); priority_queue<PII, vector<PII>, greater<PII>> Q; Q.push({0, st}); while (!Q.empty()) { int x = Q.top().second; Q.pop(); if (v[x]) continue; v[x] = 1; for (auto i : G[x]) { int y = i.first, w = i.second; int t = cal(x, y) + w; if (d[y] > t) { d[y] = t; Q.push({d[y], y}); } } } printf("%d\n", d[ed] >= inf ? 0 : d[ed]); return 0; }
- 1
信息
- ID
- 774
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 77
- 已通过
- 23
- 上传者