编程介的小学生 2017-03-20 14:37 采纳率: 20.5%
浏览 778
已采纳

Greenhound Web Service

Well, I am sure you all know Greyhound, the largest intercity bus transportation. However, few people know about Greenhound, which is actually Greyhound's mother company. It runs the expressway network. What makes Greenhound so special is that it charges the same price no matter how far you go, as long as you stay on the Greenhound expressways. As Greenhound manages a large network, it is quite convenient and economical for travelers.

In an effort to bring up the business online, a web service system is under architecture. People frequently query whether they could drive from one city to another via Greenhound expressway. Although Greenhound has a large network, it is not willing to invest too much on duplications. People would like to check about such information at the entrance to the expressway. For each query, a request is generated and posted to the Greenhound headquarter in the Silicon Valley, where its application servers reside. You are in charge of the development of the service layer, which is supposed to generate the responses.

You have your group solved the interface to external dependencies so that your focus is on the algorithm part. What you will take extra care is that Greenhound's expressways are up to certain changes. To make it simple enough to handle, all the changes during a month is fed into the system at the beginning of the month. There will not be any synchronization issue since the web service is turned off during the maintenance hours. Then, for the rest of the month, your sole responsibility is responding to the queries.

There are four kinds of change to the Greenhound network:

NEW - A new expressway is put into use. No expressways are connecting the same two cities.
DELETE - An expressway is out-dated and potentially dangerous. It is abandoned.
CLOSE - An expressway is closed for maintenance. Notice that if the expressway from city A to city B is closed, you could still get from city B to city A on the other side. Only half of the road is closed.
OPEN - A closed expressway is back into use.

Input

The first line of the input contains a single integer n (2 <= n <= 100) - the number of cities in the Greenhound network. The rest of the input contains queries or maintenance requests. (0 <= a, b < n)

N a b - A new expressway connecting city a and b is put into use.
D a b - Expressway between city a and b is abandoned.
C a b - Expressway from a to b is closed for maintenance.
O a b - Expressway from a to b is back to use.
Q a b - Query for whether it is possible to drive from city a to city b via Greenhound network.
X indicates the end of input.

Notice the initial road map is inserted at first with a few maintenance requests also.

Output

For each query, print 1 if it is possible, 0 otherwise.

Sample Input

3
N 0 1
N 1 2
Q 2 0
C 1 2
Q 2 0
Q 0 2
X

Sample Output

1
1
0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-27 14:27
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器