6
by Kavin_0409 @ 2024-07-18 10:27:46
确实奇葩
by Kavin_0409 @ 2024-07-18 10:28:16
@[hgfs](/user/1124438) 你把 cout 改成 cerr 试试
上次就有道题我代码有 ub,加上 cout 就对了,然后把 cout 改成 cerr,不开 O2 交就能 A
by nr0728 @ 2024-07-18 10:31:36
@[hgfs](/user/1124438) 你代码不是 CE 了吗,是不是直接执行编译好的源文件没注意到 CE
```
/tmp/compiler_2dz3pkft/src:16:14: 错误:use of an operand of type ‘bool’ in ‘operator++’ is forbidden in C++17
```
by nr0728 @ 2024-07-18 10:32:57
@[nr0728](/user/682739)
感谢感谢!关了o2就过了。
好像没有CE呀~~
by hgfs @ 2024-07-18 11:07:49
我喜欢链式前向星
```
#include <bits/stdc++.h>
using namespace std;
int m, n, head[5005], cnt, dis[5005];
bool vis[5005];
struct node{
int to, w, next;
}edge[400005];
void add(int u, int v, int w)
{
edge[++cnt] = {v, w, head[u]};
head[u] = cnt;
}
int main()
{
memset(head, -1, sizeof head);
memset(dis, 0x3f, sizeof dis);
cin >> m >> n;
for (int i = 1; i <= n; i++)
{
int u, v, w;
cin >> u >> v >> w;
add(u, v, w);
add(v, u, w);
}
dis[1] = 0;
int ans = 0;
for (int i = 1; i <= m; i++)
{
int x = 0;
for (int j = 1; j <= m; j++)
if (dis[j] < dis[x] && vis[j] == 0) x = j;
ans += dis[x];
vis[x] = 1;
for (int j = head[x]; j != -1; j = edge[j].next)
if (vis[edge[j].to] == 0) dis[edge[j].to] = min(dis[edge[j].to], edge[j].w);
}
for (int i = 1; i <= m; i++)
if (!vis[i])
{
cout << "orz\n";
return 0;
}
cout << ans << "\n";
return 0;
}
```
by zhaoyonghao @ 2024-08-01 08:14:35