洛谷P1339 [USACO09OCT]热浪Heat Wave

思路:裸SPFA过一遍(建议使用邻接链表存储),无向图,无向图,无向图,重要的事情要说三遍!!!蜜汁RE是什么鬼????第九个点数组开到20K,第十个点数组开到30K才AC。或许我代码写的有bug?(逃

CODE:

 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 queue<int>q;
 5 struct Edge{
 6     int pre,to,w;
 7 }edge[30000];
 8 int head[30000];
 9 bool if_q[30000];
10 int dis[30000];
11 int T, C, Ts, Te,Rs, Re,Ci;
12 int num_edge;
13 inline void add_edge(int from,int to,int w)
14 {
15     edge[++num_edge].pre=head[from];
16     edge[num_edge].to=to;
17     edge[num_edge].w=w;
18     head[from]=num_edge;
19 }
20 inline void spfa(int u)
21 {
22      q.push(u);
23      if_q[u]=true;
24      while(!q.empty())
25      {
26          u=q.front();
27          for(int i=head[u]; i!=0; i=edge[i].pre)
28          {
29              int v=edge[i].to;
30              if(dis[u]+edge[i].w<dis[v])
31              {
32                  dis[v]=dis[u]+edge[i].w;
33                  if_q[v]=true;
34                  q.push(v);
35              }
36          }
37          if_q[u]=false;
38          q.pop();
39       }
40 }
41 int main()
42 {
43     for(int i=0;i<30000;i++)
44         dis[i]=0x7fffffff;
45     cin>>T>>C>>Ts>>Te;
46     for(int i=0;i<C;i++)
47     {
48         cin>>Rs>>Re>>Ci;
49         add_edge(Rs,Re,Ci);
50         add_edge(Re,Rs,Ci);
51     }
52     dis[Ts]=0;
53     spfa(Ts);
54     cout<<dis[Te];
55     return 0;
56 }

注:就是模板题,STL大法好,哈哈哈。

时间: 2024-12-15 20:23:02

洛谷P1339 [USACO09OCT]热浪Heat Wave的相关文章

洛谷—— P1339 [USACO09OCT]热浪Heat Wave

P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to delive

洛谷 P1339 [USACO09OCT]热浪Heat Wave

题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to deliver plenty of ice cold nutritiou

P1339 [USACO09OCT]热浪Heat Wave

P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to delive

luogu P1339 [USACO09OCT]热浪Heat Wave

题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to deliver plenty of ice cold nutritiou

[最短路]P1339 [USACO09OCT]热浪Heat Wave

题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to deliver plenty of ice cold nutritiou

题解 P1339 【[USACO09OCT]热浪Heat Wave】

题目链接 这道题纯属是一个裸的SPFA: 建议先把模板AC之后再做. 只需要做一些手脚,就是在加边的时候加一个双向边就好. 然后再第一次加点的时候 看不懂模板的出门左转度娘. 推荐下面一片讲解: 友链 所以说,直接上代码. #include<iostream> #include<algorithm> #include<cstdio> #include<cstdlib> #include<queue> using namespace std; st

[USACO09OCT]热浪Heat Wave

题目链接:https://www.luogu.org/problemnew/show/P1339#sub 题目描述 德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品.Farmer John此时以先天下之忧而忧,后天下之乐而乐的精神,身先士卒地承担起向德克萨斯运送大量的营养冰凉的牛奶的重任,以减轻德克萨斯人忍受酷暑的痛苦. FJ已经研究过可以把牛奶从威斯康星运送到德克萨斯州的路线.这些路线包括起始点和终点先一共经过T (1

洛谷——P2639 [USACO09OCT]Bessie的体重问题Bessie&#39;s We…

https://www.luogu.org/problem/show?pid=2639 题目描述 Bessie像她的诸多姊妹一样,因为从Farmer John的草地吃了太多美味的草而长出了太多的赘肉.所以FJ将她置于一个及其严格的节食计划之中.她每天不能吃多过H (5 <= H <= 45,000)公斤的干草. Bessie只能吃一整捆干草:当她开始吃一捆干草的之后就再也停不下来了.她有一个完整的N (1 <= N <= 500)捆可以给她当作晚餐的干草的清单.她自然想要尽量吃到更

洛谷P1339 热浪

P1339 热浪 529通过 1.3K提交 题目提供者yeszy 标签图论福建省历届夏令营 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 求助...为什么是未知错误… 求修正,貌似死循环 第六个点和第九个点怎么了 细微之处 最短路 题目描述 德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品.Farmer John此时以先天下之忧而忧,后天下之乐而乐的精神,身先士卒地承担起向德克萨斯运送大量的营养冰凉的牛奶的重任