WuKong

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 213 Accepted Submission(s): 91
 
Problem Description
Liyuan wanted to rewrite the famous book “Journey to the West” (“Xi You Ji” in Chinese pinyin). In the original book, the Monkey King Sun Wukong was trapped by the Buddha for 500 years, then he was rescued by Tang Monk, and began his journey to the west. Liyuan thought it is too brutal for the monkey, so he changed the story:

One day, Wukong left his home - Mountain of Flower and Fruit, to the Dragon   King’s party, at the same time, Tang Monk left Baima Temple to the Lingyin Temple to deliver a lecture. They are both busy, so they will choose the shortest path. However, there may be several different shortest paths between two places. Now the Buddha wants them to encounter on the road. To increase the possibility of their meeting, the Buddha wants to arrange the two routes to make their common places as many as possible. Of course, the two routines should still be the shortest paths.

Unfortunately, the Buddha is not good at algorithm, so he ask you for help.

 
Input
There are several test cases in the input. The first line of each case contains the number of places N (1 <= N <= 300) and the number of roads M (1 <= M <= N*N), separated by a space. Then M lines follow, each of which contains three integers a b c, indicating there is a road between place a and b, whose length is c. Please note the roads are undirected. The last line contains four integers A B C D, separated by spaces, indicating the start and end points of Wukong, and the start and end points of Tang Monk respectively.

The input are ended with N=M=0, which should not be processed.

 
Output
Output one line for each case, indicating the maximum common points of the two shortest paths.
 
Sample Input
6 6
1 2 1
2 3 1
3 4 1
4 5 1
1 5 2
4 6 3
1 6 2 4
0 0
 
Sample Output
3

Hint: One possible arrangement is (1-2-3-4-6) for Wukong and (2-3-4) for Tang Monk. The number of common points are 3.
 
 
Source
2009 Multi-University Training Contest 2 - Host by TJU
 
Recommend
gaojie
 
/*
题意:给你一个图,然后给出悟空的起始位置,末位置,唐僧的初位置,末位置,然后让你计算一下,在重复最多城市
的最短路的重复城市的数量。 初步思路:dp,dp[i][j]表示从i到j重复的城市数量 */
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int mapn[][];
int dp[][];
int n,m;
int Ts,Te,Ws,We;
int u,v,val;
void floyd(){
for(int u=;u<=n;u++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(mapn[i][j]>mapn[i][u]+mapn[u][j]){
mapn[i][j]=mapn[i][u]+mapn[u][j];
dp[i][j]=dp[i][u]+dp[u][j];
}else if(mapn[i][j]==mapn[i][u]+mapn[u][j]){
dp[i][j]=max(dp[i][u]+dp[u][j],dp[i][j]);
}
}
}
}
}
void init(){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) mapn[i][j]=;
else mapn[i][j]=INF;
dp[i][j]=;
}
}
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
init();
for(int i=;i<m;i++){
scanf("%d%d%d",&u,&v,&val);
//cout<<u<<" "<<v<<" "<<val<<endl;
if(mapn[u][v]>val){//重边
mapn[u][v]=mapn[v][u]=val;
dp[u][v]=dp[v][u]=;//初始化相同的城市
}
}
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<mapn[i][j]<<" ";
// }
// cout<<endl;
// }
scanf("%d%d%d%d",&Ts,&Te,&Ws,&We);
floyd();
int res=-;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<mapn[i][j]<<" ";
// }
// cout<<endl;
// }
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(dp[i][j]>res&&( mapn[Ts][Te]==mapn[Ts][i]+mapn[i][j]+mapn[j][Te] )&&(
mapn[Ws][We]==mapn[Ws][i]+mapn[i][j]+mapn[j][We]) ){
res=dp[i][j];
// cout<<res<<endl;
}
}
}
printf("%d\n",res+);
}
return ;
}

WuKong的更多相关文章

  1. wukong搜索引擎源码解读

    转自:https://ayende.com/blog/171745/code-reading-wukong-full-text-search-engine I like reading code, a ...

  2. wukong.go

    package wukong import (     _ "github.com/boltdb/bolt"     _ "github.com/cznic/kv&quo ...

  3. hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A

    P1 : Jin Yong’s Wukong Ranking List Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Desc ...

  4. wukong引擎源码分析之索引——part 2 持久化 直接set(key,docID数组)在kv存储里

    前面说过,接收indexerRequest的代码在index_worker.go里: func (engine *Engine) indexerAddDocumentWorker(shard int) ...

  5. HDU - 2833 - WuKong

    先上题目: WuKong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. 引入Wukong让你的系统瞬间具备IOC能力

    [Github源码] 本文重点要说的是如何通过引入Wukong第三方包让自己的系统能够拥有IOC容器能力,但在具体讲解步骤之前,还是想先简单的介绍一下什么是IOC以及它存在的意义:同时也就能清楚Wuk ...

  7. 「日常训练」Jin Yong’s Wukong Ranking List(HihoCoder-1870)

    题意与分析 2018ICPC北京站A题. 题意是这样的,给定若干人的武力值大小(A B的意思是A比B厉害),问到第几行会出现矛盾. 这题不能出现思维定势,看到矛盾就是矛盾并查集--A>B.A&g ...

  8. wukong引擎源码分析之索引——part 1 倒排列表本质是有序数组存储

    searcher.IndexDocument(0, types.DocumentIndexData{Content: "此次百度收购将成中国互联网最大并购"}) engine.go ...

  9. wukong引擎源码分析之搜索——docid有序的数组里二分归并求交集,如果用跳表的话,在插入索引时会更快

    searcher.Search(types.SearchRequest{Text: "百度中国"}) // 查找满足搜索条件的文档,此函数线程安全 func (engine *En ...

随机推荐

  1. OpenStack Pike超详细搭建文档 LinuxBridge版

    前言 搭建前必须看我 本文档搭建的是分布式P版openstack(1 controller + N compute + 1 cinder)的文档. openstack版本为Pike. 搭建的时候,请严 ...

  2. ②jquery复习

    # jQuery 复习--by 传智前端与移动开发学院 ## 1. jQuery是什么?(了解)+ www.github.com+ jQuery 其实就是一堆的js函数,是普通的js,只不过应用广泛, ...

  3. 初识 JShell

    Java9 现在吵得热火朝天,赶紧顺势学习一波喽! JDK9 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk9-dow ...

  4. pdf去水印

    问: 我用Adobe acrobat professional 7.0 版想去掉添加的水印,不知道如何删除,请各位大 侠指点! 答:1.(功能表)工具→高级编辑工具→TouchUp对象工具 2.用滑鼠 ...

  5. [VirtualBox] 1、NAT模式下端口映射

    1.VirtualBox中有4中网络连接方式 VirtualBox中有4中网络连接方式:NAT.Bridged Adapter.Internal.Host-only Adapter,VMWare中有三 ...

  6. PLSQL Developer 连接oracle(64)(instantclient_32)

    下载instantclient-basic-nt-11.2.0.2.0位客户端,加压后存放,如F:\instantclient_11_2 拷贝Oracle 11.2G的msvcr80.dll和tnsn ...

  7. Python实战之dict简单练习

    ['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__forma ...

  8. ch7-列表渲染(v-for key 数组更新检测 显示过滤/排序结果)

    1 说明 我们用 v-for 指令根据一组数组的选项列表进行渲染. v-for 指令需要以 item in items 形式的特殊语法, items 是源数据数组并且 item 是数组元素迭代的别名. ...

  9. Java面向对象 线程技术--上篇

     Java面向对象   线程 知识概要:                   (1)线程与进程 (2)自定义线程的语法结构 (3)多线程概念理解 (4)多线程状态图 (5)多线程--卖票 (6)同 ...

  10. 学习笔记之08试用div做网页(滨院)-小作业

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...