题解:P16901 [CCO 2026] Waterloo Tag
SpringFullGarden · · 题解
设学生的出发点为
枚举会在哪一条边上停下(包括端点),设在
- 在边上某个位置停下,等学生到达,为了使时间最长,则两边的到达时间相同,时间为
\displaystyle\frac{g_x + g_v+w}{2v_2} 。 - 还没到达停下的位置就被追上了,时间为
\displaystyle\frac{g_x - f_x}{v_1 + v_2} 。
两个时间取小值,答案是每条边的时间的最大值。
void dij(ll s, ll *dis) {
for(ll i = 1; i <= n; i++) dis[i] = inf, vis[i] = 0;
priority_queue <pair <ll, ll> > q;
q.push({0, s}), dis[s] = 0;
while(q.size()) {
ll x = q.top().second; q.pop();
if(vis[x]) continue;
vis[x] = 1;
for(auto it : e[x]) {
ll v = it.first, w = it.second;
if(*dis && (Frac){dis[x] + w, vf} >= (Frac){g[v], vg}) continue;
if(dis[v] > dis[x] + w)
dis[v] = dis[x] + w, q.push({-dis[v], v});
}
}
}
signed main() {
n = rd(), m = rd(), vf = rd(), vg = rd();
*f = 1;
for(ll i = 1; i <= m; i++) {
ll u = rd(), v = rd(), w = rd();
e[u].push_back({v, w}), e[v].push_back({u, w});
}
for(ll k = 2; k <= n; k++) {
dij(k, g), dij(1, f);
Frac ans = {0, 1};
for(ll x = 1; x <= n; x++) if(f[x] < inf) {
for(auto it : e[x]) {
ll v = it.first, w = it.second;
Frac res = {g[x] + g[v] + w, vg + vg};
if(vf < vg) res = min(res, {g[x] - f[x], vg - vf});
res.init(), ans = max(ans, res);
}
}
cout << ans.p << '/' << ans.q << '\n';
}
return 0;
}