社区讨论
为什么要把魔法值的上限设置为 100,不能设置为 max(w[i])
P9504 『MGOI』Simple Round I | C. 魔法禁林参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo1w0c2k
- 此快照首次捕获于
- 2023/10/23 03:54 2 年前
- 此快照最后确认于
- 2023/11/03 04:23 2 年前
RT
我的想法是 , 魔法值到达 max(w[i])之后就没有必要继续增加 , 那么 max(w[i]) 应该是和 100 等价的。或者说在某些情况还进行了剪枝 , 但是为什么会得到 WA的结果呢?
第 68行注释了就会错误
CPP#include <bits/stdc++.h>
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define pb push_back
#define mem(a, b) memset((a), (b), sizeof(a))
// #define int long long
#define endl "\n"
#define io \
std::ios::sync_with_stdio(0); \
std::cin.tie(0); \
std::cout.tie(0);
using namespace std;
typedef pair<int, int> PII;
typedef unsigned long long u64;
// long long long
// 数组开够 N+10
// 有向图 or 无向图
// 多组数据,初始化
// LLLLLLLLLLLLL
const int N = 1e5 + 10, M = 1e3 + 10;
const int inf = 1e9;
const int mod = 1e9 + 7;
int n, m, idx, a, b, c, k, res;
int h[N], e[N], ne[N], de[N], w[N];
int dis[N], st[105][N];
int dp[105][N];
void add(int a, int b) {
e[idx] = b;
ne[idx] = h[a];
h[a] = idx++;
}
void add(int a, int b, int c) {
e[idx] = b;
w[idx] = c;
ne[idx] = h[a];
h[a] = idx++;
}
int s, t;
typedef pair<int, PII> my;
signed main() {
io;
mem(h, -1);
mem(dp, 0x3f);
cin >> n >> m >> t >> s;
int mx = -1;
For(i, 1, m) {
int a, b, c;
cin >> a >> b >> c;
add(a, b, c);
add(b, a, c);
mx = max(mx, c);
}
priority_queue<my, vector<my>, greater<my>> heap;
heap.push({0, {0, s}});
dp[0][s] = 0;
// cout << dp[0][s] << endl;
// 这一行 mx=100 如果注释了
// 就会 wa
mx = 100;
// cout << mx << endl;
while (heap.size()) {
auto p = heap.top();
heap.pop();
auto pp = p.second;
auto mp = pp.first;
auto x = pp.second;
if (st[mp][x])
continue;
st[mp][x] = 1;
if (mp > mx + 1)
continue;
auto d = dp[mp][x];
// cout << x << " " << mp << " " << d << endl;
for (int i = h[x]; i != -1; i = ne[i]) {
int j = e[i];
int to = mp + 1;
int cost = w[i] / (to);
if (dp[to][j] > d + cost) {
dp[to][j] = d + cost;
heap.push({dp[to][j], {to, j}});
}
}
}
res = inf;
For(i, 0, mx + 1) {
res = min(res, dp[i][t]);
}
cout << res;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...