Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路_html/css_WEB-ITnose
D. Jzzhu and Cities
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are mroads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city si (and vise versa), the length of this route is yi.
Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.
Input
The first line contains three integers n,?m,?k (2?≤?n?≤?105; 1?≤?m?≤?3·105; 1?≤?k?≤?105).
Each of the next m lines contains three integers ui,?vi,?xi (1?≤?ui,?vi?≤?n; ui?≠?vi; 1?≤?xi?≤?109).
Each of the next k lines contains two integers si and yi (2?≤?si?≤?n; 1?≤?yi?≤?109).
It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.
Output
Output a single integer representing the maximum number of the train routes which can be closed.
Sample test(s)
input
5 5 31 2 12 3 21 3 33 4 41 5 53 54 55 5
output
input
2 2 31 2 22 1 32 12 22 3
output
思路:这题只要引入一个最短路条数,然后再遍历火车线,如果最短路与火车线长度相等,此时如果最短路条数是1的话,那说明这个最短路就是火车线,不能去掉,如果最短路条数大于1条,说明除了这条火车线外还有别的跟他同样短的路,可以去掉;如果火车线长度比最短路长的话,显然可以去掉。
这题刚开始看确实挺蛋疼的,比赛的时候也没啥想法。好久不做图论方面的了,所以有点不会了。
刚才敲spfa还重新看了下这算法才会手敲,确实有点生了。
刚开始queue没过,T了。然后改成优先队列就过了。呵呵。没明白。不是dijkstra才得用优先队列么,这题为什么也要用。后面想想,应该是先后问题T了。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define INF 1000000070000using namespace std;typedef long long ll;typedef unsigned long long ull;int cnt,n,head[900005],vis[900005];int repeat[900005];//记录重复的边ll dist[900005],Map[900005];struct node{ int v,next,w;} e[900005];void add(int u,int v,int w){ e[cnt].v=v; e[cnt].w=w; e[cnt].next=head[u]; head[u]=cnt++;}void spfa(){ int i,j; priority_queue<int>q; for(i=0; idist[u]+e[i].w) { dist[e[i].v]=dist[u]+e[i].w; repeat[e[i].v]=repeat[u]; if(!vis[e[i].v]) { vis[e[i].v]=1; q.push(e[i].v); } } else if(dist[e[i].v]==dist[u]+e[i].w) { repeat[e[i].v]+=repeat[u]; if(repeat[e[i].v]>=2) repeat[e[i].v]=2; } } }}int main(){ int m,k,i,j,u,v,w,sum=0;//sum表示需要保留的火车线路 mem(head,-1); cin>>n>>m>>k; for(i=0;iw) Map[v]=w; } for(i=1; i <br> <br> <p></p> <p><br> </p> </int></bitset></set></queue></map></algorithm></cstring></cstdio></iostream>

HTML、CSS和JavaScript在Web开发中的作用分别是:1.HTML定义网页结构,2.CSS控制网页样式,3.JavaScript添加动态行为。它们共同构建了现代网站的框架、美观和交互性。

HTML的未来充满了无限可能。1)新功能和标准将包括更多的语义化标签和WebComponents的普及。2)网页设计趋势将继续向响应式和无障碍设计发展。3)性能优化将通过响应式图片加载和延迟加载技术提升用户体验。

HTML、CSS和JavaScript在网页开发中的角色分别是:HTML负责内容结构,CSS负责样式,JavaScript负责动态行为。1.HTML通过标签定义网页结构和内容,确保语义化。2.CSS通过选择器和属性控制网页样式,使其美观易读。3.JavaScript通过脚本控制网页行为,实现动态和交互功能。

HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增强WebevebDevelopment。

HTML是构建网页结构的基石。1.HTML定义内容结构和语义,使用、、等标签。2.提供语义化标记,如、、等,提升SEO效果。3.通过标签实现用户交互,需注意表单验证。4.使用、等高级元素结合JavaScript实现动态效果。5.常见错误包括标签未闭合和属性值未加引号,需使用验证工具。6.优化策略包括减少HTTP请求、压缩HTML、使用语义化标签等。

HTML是一种用于构建网页的语言,通过标签和属性定义网页结构和内容。1)HTML通过标签组织文档结构,如、。2)浏览器解析HTML构建DOM并渲染网页。3)HTML5的新特性如、、增强了多媒体功能。4)常见错误包括标签未闭合和属性值未加引号。5)优化建议包括使用语义化标签和减少文件大小。

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的作用是通过标签和属性定义网页的结构和内容。1.HTML通过到、等标签组织内容,使其易于阅读和理解。2.使用语义化标签如、等增强可访问性和SEO。3.优化HTML代码可以提高网页加载速度和用户体验。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

记事本++7.3.1
好用且免费的代码编辑器

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)