## sicily 1031 Campus 原

Ciel

### Description

At present, Zhongshan University has 4 campuses with a total area of 6.17 square kilometers sitting respectively on both sides of the Pearl River or facing the South China Sea. The Guangzhou South Campus covers an area of 1.17 square kilometers, the North Campus covers an area of 0.39 square kilometers, the Guangzhou East Campus has an area of 1.13 square kilometers and the Zhuhai Campus covers an area of 3.48 square kilometers. All campuses have exuberance of green trees, abundance of lawns and beautiful sceneries, and are ideal for molding the temperaments, studying and doing research.

Sometime, the professors and students have to go from one place to another place in one campus or between campuses. They want to find the shortest path between their source place S and target place T. Can you help them?

### Input

The first line of the input is a positive integer C. C is the number of test cases followed. In each test case, the first line is a positive integer N (0<N<=100) that represents the number of roads. After that, N lines follow. The i-th(1<=i<=N) line contains two strings Si, Ti and one integer Di (0<=Di<=100). It means that there is a road whose length is Di between Si and Ti. Finally, there are two strings S and T, you have to find the shortest path between S and T. S, T, Si(1<=i<=N) and Ti(1<=i<=N) are all given in the following format: str_Campus.str_Place. str_Campus represents the name of the campus, and str_Place represents the place in str_Campus. str_Campus is "North", "South", "East" or "Zhuhai". str_Place is a string which has less than one hundred lowercase characters from "a-z". You can assume that there is at most one road directly between any two places.

### Output

The output of the program should consist of C lines, one line for each test case. For each test case, the output is a single line containing one integer. If there is a path between S and T, output the length of the shortest path between them. Otherwise just output "-1" (without quotation mark). No redundant spaces are needed.

### Sample Input

``````1
2
South.xiaolitang South.xiongdelong 2
South.xiongdelong Zhuhai.liyuan 100
South.xiongdelong South.xiaolitang``````

### Sample Output

``2``

## 代码：

``````// Problem#: 1031
// Submission#: 1789656
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;

#define MAX 210
#define INF 1000000

int buffer[MAX][MAX];
int len[MAX];
bool judge[MAX];

int dijkstra( int b, int e, int n ){
memset(judge,0,sizeof(judge));
for( int i=0 ; i<n ; i++ )
len[i] = INF;
len[b] = 0;
for( int i=0 ; i<n ; i++ ){
int min = INF;
int v = b;
for( int j=0 ; j<n ; j++ )
if( !judge[j] && len[j]<min ){
min = len[j];
v = j;
}
judge[v] = true;
for( int j=0 ; j<n ; j++ )
if( !judge[j] && len[v]+buffer[v][j]<len[j] )
len[j] = len[v]+buffer[v][j];
}
if( judge[e]) return len[e];
else return -1;
}

int main(){
int c,n,l;
string b,e;
cin >> c;
while( c-- ){
cin >> n;
map<string,int> sysu;
int num = 0;
for( int i=0 ; i<MAX ; i++ )
for( int j=0 ; j<MAX ; j++ )
buffer[i][j] = (i==j?0:INF);
for( int i=0 ; i<n ; i++ ){
cin >> b >> e >> l;
if( !sysu.count(b) ) sysu[b] = num++;
if( !sysu.count(e) ) sysu[e] = num++;
buffer[sysu[b]][sysu[e]] = buffer[sysu[e]][sysu[b]] = l;
}
cin >> b >> e;
if( b==e ) cout << 0 << endl;
else if( !sysu.count(b) || !sysu.count(e) ) cout << -1 << endl;
else cout << dijkstra(sysu[b],sysu[e],num) << endl;
}
return 0;
}``````

### Ciel

--============Oracle ADG搭建============== --==========准备阶段========= 1.检查primary为archivelog模式。 select log_mode from v\$database; 如果为noarchivelog模式，切换到archivelo......

UltraSQL
2018/07/23
0
0
Eclipse Memory Analyzer tool 工具的使用

1、前言 在使用阿里云的OSS服务时，服务器内存高居不下，导致服务异常，最终通过Jmap+MAT找到了内存溢出的方法，定位到了问题所在。 整体思路是先用Jmap从生产上dump下来内存快照，然后用Mat...

freeli
2017/10/31
1K
1

2013/10/31
2K
1
sicily 1150 简单魔板 sicily 1151 魔板 sicily 1515 魔板C

Ciel
2012/12/15
949
1
sicily 1150,1151

2014/10/12
95
0

zk中ToBeAppliedRequestProcessor解析

ToBeAppliedRequestProcessor在Leader中 在已处理事务和最后处理事务处理器之间，处理器链上下一个是FinalRequestProcessor public void processRequest(Request request) throws RequestPro...

33分钟前
3
0
Allegro快捷键设置-PCB环境

demyar
34分钟前
3
0
idea maven web项目启动build时报错java.lang.NullPointerException

38分钟前
3
0
weed3-2.3.1.查询之输出

Weed3 一个超轻量级ORM框架（只有0.1Mb哦） 源码：https://github.com/noear/weed3 源码：https://gitee.com/noear/weed3 查询可是个复杂的话题了，可能我们80%的数据库处理都在查询。 今天先...

38分钟前
3
0
【Android JetPack系列】数据绑定：DataBinding

Agnes2017
47分钟前
3
0