Problem E. Spaceship Defence

本挑战涉及在一个复杂的太空船环境中进行战术模拟。士兵们利用不同颜色编码的传送器和涡轮升降机来移动,以实现从起点到终点的最短路径。任务包括分析房间布局、传送设施及移动限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The contest is over. You will be able to try solving the problems for practice soon.
Small input
10 points
The contest is finished.
Large input
14 points
The contest is finished.

Problem

The enemy has invaded your spaceship, and only superior tactics will allow you to defend it! To travel around your spaceship, your soldiers will use two devices: teleporters andturbolifts.

Teleporters allow your soldiers to move instantly between rooms. Every room contains a teleporter, and rooms are color-coded: if a soldier is in a room with some color, she can use the teleporter in that room to immediately move to any other room with the same color.

Turbolifts allow your soldiers to move between rooms more slowly. A turbolift is like an elevator that moves in many directions. Each turbolift moves from one room to one other room, and it takes a certain amount of time to travel. Notes about turbolifts:

  • Turbolifts are not two-way: if a turbolift moves soldiers from room a to room b, the same turbolift cannot move soldiers from room b to room a, although there might be another turbolift that does that.
  • More than one soldier can use the same turbolift, and they do not interfere with each other in any way.

You will be given the locations and destinations of several soldiers. For each soldier, output the minimum amount of time it could take that soldier to travel from his location to his destination.

Input

The first line of the input gives the number of test cases, TT test cases follow.

For every test case:

The first line of every test case contains an integer N, which is the number of rooms in your spaceship. The rooms are numbered from 1 to N. The following N lines each contain a string telling the color of the rooms, from room 1 to room N. The strings only contain characters a-z (the lower-case English letters) and 0-9 (the number 0 to 9), and the length of each string will be less than or equal to 2.

The next line in the test case is an integer M, which indicates the number of turbolifts in your spaceship. The following M lines each contain 3 space-separated integers aibiti, telling us that there is a turbolift that can transport soldiers from room ai to room bi in tiseconds.

The next line in the test case contains an integer S, which is the number of soldiers at your command. The following S lines each contain two integers: the location and destination of one soldier, pj and qj.

Output

For each test case, output one line containing only the string "Case #x:", where x is the number of the test case (starting from 1). On the next S lines, output a single integer: on line j, the smallest number of seconds it could take for a soldier to travel from pj to qj. If there is no path from pj to qj, the integer you output should be -1.

Limits

1 ≤ S ≤ 100.
1 ≤ ai, bi ≤ N.
0 ≤ ti ≤ 1000.
1 ≤ pj, qj ≤ N.

Small dataset

1 ≤ T ≤ 10.
1 ≤ N ≤ 1000.
0 ≤ M ≤ 3000.

Large dataset

T = 1.
1 ≤ N ≤ 80000.
0 ≤ M ≤ 3000.

Sample


Input 
 

Output 
 
3
3
gl
t3
t3
3
1 2 217
3 2 567
1 1 21
2
2 1
2 3
4
ca
bl
bl
8z
0
3
1 2
2 3
1 1
8
re
b7
ye
gr
0l
0l
ye
b7
7
4 1 19
2 4 21
2 5 317
4 5 34
4 7 3
4 8 265
8 6 71
3
4 3
2 6
1 4
<think>好的,我现在需要帮助用户解决如何注册Spaceship相关的域名的问题。首先,我应该回顾用户提供的引用内容,特别是引用[1]和引用[2],因为这些是用户提供的站内资料,必须被合理引用。 用户的问题是关于使用Spaceship注册域名的方法,而引用[1]中提到了Spaceship的API示例,包括查询域名可用性和注册的代码片段。引用[2]则涉及域名转移的步骤,可能对用户的问题有帮助,但用户主要关注的是注册,所以可能需要更侧重于引用[1]的内容。 接下来,我需要确保回答结构清晰,分步骤说明。根据用户提供的示例,回答需要包括步骤说明、代码示例、注意事项以及相关问题。同时,按照系统级指令,所有数学表达式要用正确的LaTeX格式,但在这个问题中可能用不到数学公式,但需要确保代码块格式正确。 首先,要确认Spaceship域名注册的基本步骤。根据引用[1],使用API的流程是先检查域名可用性,再注册。所以步骤可能分为:1. 准备工作(安装SDK、获取API密钥);2. 查询可用性;3. 注册域名。同时,引用[2]提到域名转移可能需要解锁域名和获取转移码,但注册过程可能不需要这些,但作为注意事项可以提及后续维护或转移时的步骤。 然后,要检查用户提供的代码示例是否正确。引用[1]中的代码是否正确?比如,导入的模块是否正确,方法名是否符合常规命名习惯。例如,DomainManager类是否有check_availability和register方法。用户示例中的代码可能需要进一步验证,但根据用户提供的内容,直接引用即可,但可能需要提醒用户确保安装正确的库或SDK。 另外,注意事项部分需要包括API密钥的安全、域名注册规则(如有效期、续费)、以及可能的转移步骤(如引用[2]中的解锁域名)。这里需要将引用[2]的内容自然地融入注意事项中,例如在维护域名时可能需要转移,此时需要按照引用[2]的步骤操作。 生成的相关问题需要围绕Spaceship域名服务展开,比如如何管理已注册的域名、如何续费、如何转移注册商等。这些问题应基于引用内容,特别是引用[2]提到的转移流程。 最后,确保回答符合用户可见层的格式要求:结构清晰,分步骤,真实可靠,并正确添加引用标识。引用标识应放在相关内容的末尾,如步骤中的代码部分引用[^1],注意事项中的转移部分引用[^2]。 现在需要将这些思考整理成一个连贯的回答,确保每个部分都覆盖到,并且引用正确。同时,检查是否有遗漏的信息,比如是否需要提醒用户关于API权限或错误处理的问题。此外,确认代码示例的语法是否正确,比如Python的缩进和函数调用是否正确。如果用户提供的代码示例中有潜在的拼写错误,是否需要修正?根据用户提供的示例,可能不需要修改,直接引用即可,但可以建议用户参考官方文档以获取最新信息。</think>### 如何注册Spaceship相关域名 以下是使用Spaceship API注册域名的详细步骤: --- #### **步骤1:环境准备** 1. **安装Spaceship SDK** 确保已安装官方提供的Python SDK,可通过以下命令安装: ```bash pip install spaceship-sdk ``` 2. **获取API密钥** 登录Spaceship控制台,生成API密钥并保存(需妥善保管密钥)。 --- #### **步骤2:查询域名可用性** 使用`DomainManager`类的`check_availability`方法检查目标域名(如`example.com`)是否可注册: ```python from spaceship.domain import DomainManager # 初始化域名管理对象 domain_manager = DomainManager(api_key="your_api_key") # 查询域名状态 domain_name = "example.com" availability = domain_manager.check_availability(domain_name) print(f"域名 {domain_name} 的可用性:{availability}") ``` - 返回值为`True`表示可注册,`False`表示已被占用。 --- #### **步骤3:注册域名** 若域名可用,调用`register`方法完成注册: ```python if availability: # 注册域名(需提供必要信息如所有者邮箱、支付方式等) registration_result = domain_manager.register( domain_name, owner_email="user@example.com", payment_method="credit_card" # 或绑定预存账户 ) print(f"域名 {domain_name} 注册成功!注册ID:{registration_result.id}") else: print("域名不可用,请尝试其他名称。") ``` [^1] --- #### **注意事项** 1. **API密钥安全** 避免将密钥硬编码在代码中,建议通过环境变量或配置文件读取。 2. **域名注册规则** - 域名注册后需在5天内完成DNS解析配置,否则可能被释放。 - 注册时长默认为1年,可通过参数`duration`调整。 3. **域名转移** 若需将已有域名转移到Spaceship,需在原注册商处解锁域名并获取转移码。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值