当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3065:Stargates

题目描述
"A Long Time Ago, in a Galaxy Far, Far Away..." one advanced civilization discovered a manner of instant traveling between solar systems. Since that moment, they have devoted all their efforts to constructing pairs of stargates that connect distant planets. Soon enough communication network became so complex that they require help to maintain information about the connected worlds.

Write a program that will help them maintain information about the connected systems and we will make sure that the best of your solutions will be forwarded to their space-time continuum. Planets A and B are connected if there is a direct stargate connection between them, or there is a planetsequence P1, P2,..Pn where P1=A, Pn=B and there is a direct stargate connection between Pk and Pk-1, k Î{2..n} . Connections are bidirectional. There can be multiple connection paths between two planets.
输入解释
Input file consist of multiple data sets. Each data set occupies one or more lines. There are no empty lines in the input file. Each line starts with a single letter 'D', 'C' or 'Q' (upper or lower case) followed by 1 to 5 integers with following meaning:
'D' (define) has only one argument which defines number of planets N considered in following data set (N<=6000000, planets are numerated from 1..N).
'C' (connect) creates a connection between a given pair(s) of planets.
'Q' (query) examines if a given pair(s) of planets are connected.
Both 'C' and 'Q' command ('X' in following text) share the same syntax:
X src dst – Creates a connection (or query) between given pair of planets (src, dst).
X src dst nnn – Creates a connection (or query) between src planet and nnn consecutive planets numerated from dst.
Example: X 1 100 3 creates following links (1,100), (1,101), (1,102).
X src dst nnn step – Creates a connection (or query) between src planet and nnn planets numerated from dst with given step.
Example: X 1 100 3 5 creates following links (1,100), (1,105), (1,110).
X src dst nnn dststep srcstep – Creates a connection (or query) between nnn pairs of planets numerated from src with srcstep and dst with dststep respectively.
Example: X 1 100 3 5 15 creates following links (1,100), (16,105), (31,110).
输出解释
Output file contains one line pre each query ('Q') line in the input file. Each line contains two numbers separated by space dash space sequence. First value represents number of connected planet pairs from appropriate query while second represents number of disconnected planet pairs.
输入样例
d 5
C 1 3
D 20
q 1 3
c 1 10 10
Q 1 2 18 1 1
输出样例
0 - 1
9 - 9

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3065

最后修改于 2020-10-29T06:51:37+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536