spfaWA了三个点,跪了

P1529 [USACO2.4] 回家 Bessie Come Home

感谢各位大牛指点,谢谢啊谢谢
by _H1kar1 @ 2019-06-09 14:39:18


~~能用一下链式前向星么?~~
by CrazyDance @ 2019-06-09 15:09:54


```cpp int edgenum = 0; struct Edge { int head, to, val, nxt; Edge() { head = 0; to = 0; val = 0; nxt = 0; } }edge[10005] void addedge(int from, int to, int v) { edge[++edgenum].to = to; edge[edgenum].val = v; edge[edgenum].nxt = edge[from].head; edge[from].head = edgenum; } ```
by Smallbasic @ 2019-06-09 15:18:52


用邻接表吧
by Smallbasic @ 2019-06-09 15:20:10


而且没判负环
by Smallbasic @ 2019-06-09 15:20:40


哦题目没有负环
by Smallbasic @ 2019-06-09 15:24:12


那就用$dijkstra$试一下,没负权边就没必要用$SPFA$,况且这题不用堆优化都能过
by Smallbasic @ 2019-06-09 15:29:24


```cpp int mins=0x3f3f3f3f; int minn=0; for(int i=65;i<=127;i++){ if(hc[i]) { spfa(i); if(dis[90]<mins){ mins=dis[90]; minn=i; } } } cout<<(char)minn<<" "<<mins<<endl; ``` 本蒟蒻的主题除SPFA的代码
by charliegong @ 2019-06-09 16:21:24


|