题目传送门:http://codevs.cn/problem/1817/
这题可以说是Floyd的最终考验吧?
具体来说:做了这题Floyd的原理就完全明白了吧!
详细请参考《算导》P405吧!(难得算导说了一次人话)
#include<iostream> #include<cstdio> #include<vector> #define INF 1000099 using namespace std; struct abc{int point,len;}; int n,m; int t[299]={0}; int f[299][299]; bool yet[299]={0}; vector<abc> path[299]; bool day[100099]={0}; int pro=0; void init(){ for (int i=1;i<=250;i++){ t[i]=INF; } for (int i=0;i<=250;i++){ for (int j=0;j<=250;j++){ f[i][j]=INF; } } scanf("%d%d",&n,&m); for (int i=1;i<=n;i++){ scanf("%d",&t[i]); if (t[i]==0) yet[i]=true; } abc hc; for (int i=1,a,b,leng;i<=m;i++){ scanf("%d%d%d",&a,&b,&leng); a++;b++; f[a][b]=leng;f[b][a]=leng; hc.point=b;hc.len=leng; path[a].push_back(hc); hc.point=a; path[b].push_back(hc); } } void update(int num){ int end,length; for (int k=pro+1;k<=end;k++) yet[k]=true; for (int k=pro+1;k<=end;k++){ for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ f[i][j]=min(f[i][j],f[i][k]+f[k][j]); } } } pro=end; } int main(){ int Q,x,y,ti; init(); cin>>Q; for (int i=1;i<=Q;i++){ scanf("%d%d%d",&x,&y,&ti); x++;y++; if (!day[ti]) { update(ti); day[ti]=1; } if (f[x][y]<INF && yet[x] && yet[y]) printf("%d\n",f[x][y]); else printf("-1\n"); } return 0; }
为什么去年写的代码这么丑? (╯‵□′)╯︵┻━┻
Awesome article.Really thank you! Awesome.
Enjoyed every bit of your blog.Thanks Again. Will read on…
Fantastic blog. Awesome.
I really like and appreciate your article post.Thanks Again. Great.
Enjoyed every bit of your blog.Much thanks again. Great.
Awesome blog post.Really thank you! Cool.
Very neat article.Really thank you! Really Cool.
wow, awesome article post.Really thank you!
I really enjoy the blog.Really looking forward to read more. Will read on…
Awesome blog post.Really thank you!
I think this is a real great blog.Much thanks again. Fantastic.
Enjoyed every bit of your article.Thanks Again.
I truly appreciate this post.Thanks Again. Really Great.
Looking forward to reading more. Great post.Much thanks again. Keep writing.
I believe everybody went like Ones New website, reason being things like this site without doubt has a article on quality. I loved read A New content. go on To remain a useful article, I will avail Once more by One additional time. Bless you.
Thanks-a-mundo for the post.Thanks Again. Fantastic.
I really enjoy the post.Thanks Again. Really Great.
I really like and appreciate your post. Awesome.
Highly descriptive article, I loved that a
lot. Will there be a part 2?
A big thank you for your post. Keep writing.
Thanks for the blog post.Thanks Again. Want more.
I’m extremely inspired with your writing talents as neatly as with the layout on your weblog.
Is that this a paid theme or did you modify it yourself?
Either way stay up the nice high quality writing, it’s uncommon to see
a great blog like this one today..
I really like and appreciate your blog.Thanks Again. Much obliged.
I really like and appreciate your article post.Really thank you! Great.
Major thanks for the article post.Thanks Again. Much obliged.
wow, awesome blog article. Much obliged.
Hi i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make comment
due to this sensible post.
Major thanks for the blog. Awesome.
Thanks a lot for the article.Thanks Again. Really Great.
This is one awesome blog post.Really thank you! Great.
Hey, thanks for the blog article.Really thank you! Will read on…
Really appreciate you sharing this blog article.Thanks Again.
I know this if off topic but I’m looking into starting my own weblog and was
wondering what all is required to get set up?
I’m assuming having a blog like yours would cost a pretty penny?
I’m not very web smart so I’m not 100% certain. Any tips or advice would be greatly
appreciated. Many thanks
Very informative blog.Thanks Again. Really Cool.
wow, awesome blog post. Keep writing.
Wow, great blog post.Really thank you! Really Cool.
I am so grateful for your blog post.Really thank you! Cool.
Heya i am for the first time here. I came across this board and I find It truly useful & it helped
me out a lot. I hope to give something back and help others
like you helped me.
Im obliged for the post.Much thanks again. Much obliged.
Im obliged for the article. Keep writing.
Awesome blog you have here but I was wondering
if you knew of any user discussion forums that cover the same topics talked about here?
I’d really love to be a part of group where I can get feedback from other knowledgeable
people that share the same interest. If you have any recommendations, please let me
know. Thanks a lot!
Thank you ever so for you post.Really looking forward to read more.
Really enjoyed this article post.Much thanks again. Fantastic.
Thanks for sharing, this is a fantastic blog post.Thanks Again. Awesome.
Great, thanks for sharing this post. Much obliged.
I loved your blog.Really thank you! Awesome.
Appreciate you sharing, great article post.Much thanks again. Great.
Looking forward to reading more. Great blog.Really looking forward to read more. Great.
I am curious to find out what blog system you have been working with?
I’m experiencing some minor security issues with my latest site
and I’d like to find something more safe. Do you have
any recommendations?
A big thank you for your blog post. Really Cool.
It’s going to be ending of mine day, but before finish I
am reading this impressive post to improve my experience.
Thanks for the article.Really thank you! Really Cool.
Fantastic blog post. Fantastic.
Great, thanks for sharing this article.Thanks Again. Great.
I every time spent my half an hour to read this web site’s posts daily along
with a mug of coffee.
I cannot thank you enough for the article.Really looking forward to read more. Fantastic.
wow, awesome article.Much thanks again. Will read on…
Everything is very open with a very clear clarification of the challenges.
It was truly informative. Your site is very useful.
Thank you for sharing!
Perfectly written content material, Really enjoyed studying.
Im thankful for the blog.Thanks Again. Really Cool.
Im obliged for the blog.Much thanks again. Want more.
Really enjoyed this blog.Much thanks again. Fantastic.
I know this if off topic but I’m looking into starting my own weblog
and was wondering what all is required to get set up?
I’m assuming having a blog like yours would cost a pretty penny?
I’m not very web savvy so I’m not 100% positive. Any tips
or advice would be greatly appreciated. Thanks
I truly appreciate this blog article.Thanks Again.
A round of applause for your blog article.Much thanks again. Great.
Looking forward to reading more. Great post.Really thank you! Keep writing.
A round of applause for your article.Really thank you! Much obliged.
I loved your article.Really looking forward to read more. Much obliged.
Really appreciate you sharing this post. Really Cool.
I really enjoy the blog.Thanks Again.
Im thankful for the post. Fantastic.
I truly appreciate this blog.Thanks Again.
Hey, thanks for the article. Fantastic.
Fantastic article.Much thanks again.
I really enjoy the blog.Really thank you! Will read on…
This is one awesome blog. Really Cool.
Really appreciate you sharing this article post. Really Cool.
I constantly spent my half an hour to read this website’s articles everyday along with a mug of coffee.
Thanks for every other great post. The place else could anybody get that type of information in such an ideal method of
writing? I’ve a presentation next week, and I am on the search for such
info.
I appreciate you sharing this blog post.Much thanks again. Much obliged.
Im thankful for the blog article.Really looking forward to read more. Great.
Hi there! I know this is kind of off topic but I was wondering which blog platform are you using for this site?
I’m getting sick and tired of WordPress because I’ve had issues with hackers and
I’m looking at options for another platform.
I would be awesome if you could point me in the direction of a good platform.
Appreciate you sharing, great article post.Really thank you! Want more.
Great, thanks for sharing this blog post. Much obliged.
I am so grateful for your blog post. Will read on…
This is a really good tip particularly to those fresh to the blogosphere.
Short but very precise info… Appreciate your sharing this one.
A must read post!
Thanks a lot for the article.Really thank you! Will read on…
Fantastic blog article.Thanks Again. Cool.
Major thanks for the blog.Thanks Again.
Great article. Cool.
I loved your blog post.Really looking forward to read more. Great.
Thank you for your article post.Much thanks again. Fantastic.
I really like and appreciate your blog article. Really Great.
Thanks again for the article.Really thank you! Keep writing.
Fantastic blog.Really thank you! Really Great.
Really enjoyed this blog article.Thanks Again. Cool.
I truly appreciate this blog article. Much obliged.
I really enjoy the article post.Thanks Again. Fantastic.
A round of applause for your blog.Much thanks again. Keep writing.
Really enjoyed this article.Thanks Again. Great.
Thanks a lot for the article.Thanks Again. Keep writing.
Really informative blog article.Thanks Again. Awesome.
What i do not understood is actually how you are now not actually a lot more smartly-liked than you may be
now. You are so intelligent. You realize therefore significantly relating to this topic, produced me personally
consider it from so many numerous angles. Its like men and women aren’t interested until it’s something to do with Woman gaga!
Your own stuffs great. At all times care for it up!
Thanks for sharing, this is a fantastic blog.Much thanks again. Great.
Thank you for your article.Much thanks again. Great.
Great, thanks for sharing this post.Really thank you! Cool.
Thanks-a-mundo for the article.Much thanks again. Fantastic.
Thank you ever so for you article post.Thanks Again. Keep writing.
Im thankful for the blog.Thanks Again. Awesome.
I really liked your article.Thanks Again. Great.
Very good blog.Much thanks again. Keep writing.
I loved your article.Really thank you! Great.
Very neat article.Really thank you! Keep writing.
wow, awesome article. Will read on…
Major thankies for the post.Really thank you! Will read on…
Thanks a lot for the blog post. Really Cool.
Im thankful for the blog.Thanks Again. Cool.
This is very interesting, You are a very skilled blogger.
I’ve joined your rss feed and look forward to seeking more of your
magnificent post. Also, I’ve shared your web site in my social networks!
wow, awesome blog article. Cool.
wow, awesome article post.Thanks Again. Fantastic.
Im thankful for the article.Much thanks again. Awesome.
wow, awesome blog post.Much thanks again. Cool.
This is one awesome article.Thanks Again.
Very informative blog.Really looking forward to read more. Really Cool.
wow, awesome blog article.Really thank you! Want more.
Say, you got a nice article post. Keep writing.
Thanks so much for the blog post.Really looking forward to read more. Want more.
I really liked your blog article.Thanks Again. Will read on…
Looking forward to reading more. Great article post.Much thanks again. Want more.
Im thankful for the blog article.Really thank you! Great.
Great article.Really thank you! Want more.
A round of applause for your article post.Thanks Again. Will read on…
Enjoyed every bit of your article.Much thanks again. Really Great.
It’s very easy to find out any matter on web as compared to textbooks,
as I found this paragraph at this site.
Very informative blog.Really looking forward to read more. Great.
Thanks for sharing, this is a fantastic blog. Really Great.
Appreciate you sharing, great blog.Much thanks again. Fantastic.
I truly appreciate this blog.Much thanks again. Great.
I think this is a real great blog article. Want more.
Very good blog article.Much thanks again. Much obliged.
I loved your article.Thanks Again. Awesome.
I cannot thank you enough for the blog post.Really thank you! Want more.
I really like and appreciate your blog post. Really Great.
I cannot thank you enough for the blog.Thanks Again. Much obliged.
Would love to incessantly get updated great website! .
Really enjoyed this article post.Much thanks again. Will read on…
Thanks so much for the post. Keep writing.
Really enjoyed this article.Really thank you! Really Cool.
Hey, thanks for the article post. Much obliged.
Thanks-a-mundo for the blog.Really thank you! Cool.
I really enjoy the article post.Really thank you! Will read on…
Thanks again for the blog article.Really looking forward to read more. Want more.
Great blog article. Much obliged.
A round of applause for your article.Thanks Again. Much obliged.
Major thankies for the blog.Really looking forward to read more. Want more.
Very good post.Thanks Again. Keep writing.
Muchos Gracias for your article. Awesome.
Thanks a lot for the post.Much thanks again. Want more.
Im thankful for the article.Thanks Again. Will read on…
Really informative blog post.Really looking forward to read more. Really Cool.
Thanks again for the blog.Really looking forward to read more. Awesome.
I am so grateful for your blog post.Thanks Again. Want more.
I really liked your post.Really thank you! Keep writing.
Say, you got a nice blog. Want more.
Im thankful for the blog post.Really looking forward to read more. Really Great.
Say, you got a nice post.Much thanks again. Want more.
wow, awesome post.Really looking forward to read more. Great.
A round of applause for your blog.Really thank you! Will read on…
Im obliged for the post.Really thank you! Really Cool.
I think this is a real great post.Thanks Again. Fantastic.
Fantastic blog post. Want more.
Very informative blog post.Really thank you! Really Cool.
Awesome blog article.Thanks Again. Cool.
Great, thanks for sharing this article post.Really thank you! Fantastic.
This is one awesome post.Thanks Again. Cool.
Thanks for sharing, this is a fantastic article post.Really looking forward to read more. Fantastic.
I cannot thank you enough for the post.Thanks Again. Want more.
Thanks for the article.Really looking forward to read more. Great.
I cannot thank you enough for the post.Really looking forward to read more. Will read on…
wow, awesome blog post.Really thank you!
wow, awesome article post.Much thanks again. Really Cool.
Really enjoyed this post.Thanks Again. Will read on…
Muchos Gracias for your article post.Really thank you! Great.
Great blog article.Really looking forward to read more. Will read on…
Im thankful for the post.Really thank you! Great.
wow, awesome blog.Thanks Again. Much obliged.
I really like and appreciate your article.Really looking forward to read more. Much obliged.