题目描述

Bob, who is a network administrator, supervises a network of computers. He is keeping a log connections between the computers in the network. Each connection is bi-directional. Two computers are interconnected if they are directly connected or if they are interconnected with the same computer. Occasionally, Bob has to decide, quickly, whether two given computers are connected, directly or indirectly, according to the log information.

Write a program which based on information input from a text file counts the number of successful and the number of unsuccessful answers to the questions of the kind :

is computeri​ interconnected with computerj​


输入输出格式

输入格式

The program reads data from a text file, as follows:

  1. The number of computers in the network (a strictly positive integer);
  2. A list of pairs of the form: (a) c computeri​ computerj​ , where computeri​ and computerj​ are integers from 1 to no of computers. A pair of this form shows that computeri​ and computerj​ get interconnected.(b) q computeri​ computerj​ , where computeri​ and computerj​ are integers from 1 to no of computers. A pair of this form stands for the question:

Each pair is on a separate line. Pairs can appear in any order, regardless of their type. The log is updated after each pair of type (a) and each pair of type (b) is processed according to the current network configuration.

For example, the input file illustrated in the sample below corresponds to a network of 10 computers and 7 pairs. There are N1 successfully answered questions and N2 unsuccessfully answered questions. The program prints these two numbers to the standard output on the same line, in the order: successful answers, unsuccessful answers, as shown in the sample output.

输出格式

The program prints two integer numbers to the standard output on the same line, in the order: ‘successful answers, unsuccessful answers’, as shown in the sample output.


输入输出样例1

输入

  1. 10
  2. c 1 5
  3. c 2 7
  4. q 7 1
  5. c 3 9
  6. q 9 6
  7. c 2 5
  8. q 7 5
  9. 0

输出

  1. 1,2

解题思路:

#include <stdio.h>
#define MN 10000
int n, i;
int con, ncon;
struct vertex
{struct vertex *father;int size;
};
struct vertex v[MN];
char buf[100];
struct vertex *find (int i)
{struct vertex *pv = v + i, *av, *rv;for (av = pv; av->father; av = av->father)continue;rv = av;for (av = pv; av != rv; av = pv){pv = av->father;av->father = rv;}return rv;
}
void join(struct vertex *v1, struct vertex *v2)
{if (v1 == v2)return;if (v1->size < v2->size)v1->father = v2;elsev2->father = v1;
}
int main(void)
{char c[2];int f, t;gets (buf);while (1){sscanf (buf, "%d", &n);if (n == 0)return 0;for (i = 0; i < n; i++){v[i].father = NULL;v[i].size = 1;}con = ncon = 0;while (1){gets (buf);if (*buf == 'c'){sscanf (buf, "%s %d %d", c, &f, &t);join (find (f - 1), find (t - 1));}else if (*buf == 'q'){sscanf (buf, "%s %d %d", c, &f, &t);if (find (f - 1) == find (t - 1))con++;elsencon++;}else{printf ("%d,%d\n", con, ncon);break;}}}
}

Network Connections相关推荐

  1. 17.2.20 Sparsifying Neural Network Connections for Face Recognition 小感

    首先作为自己的第一篇博客,不为别的.在大致读了 > <Sparsifying Neural Network Connections for Face Recognition> 本文主 ...

  2. win10 无法启动network connections

    在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Netman\Parameters下建两个项: 名称ServiceDll,类dao型REG_ ...

  3. Unity NetWork

    using UnityEngine; using System.Collections;public class NetworkTest : MonoBehaviour {int myPort = 1 ...

  4. Lidgren.Network – an introduction to networking in C# games

    Lidgren.Network – an introduction to networking in C# games http://genericgamedev.com/tutorials/lidg ...

  5. Transmitting Network Data Using Volley(使用Volley框架传输网络数据)

    前面看了某大神关于Volley框架的文章,难怪说不要国内的技术文章,看了Google的官方文档,我才知道,心目中的大神还是有很多不足的地方.所以,对着英文,自己学习下. Volley is an HT ...

  6. 使用 Web 高速缓存减少网络流量 / Reducing network traffic with Web caching

    使用 Web 高速缓存减少网络流量 / Reducing network traffic with Web caching English Version Reducing network traff ...

  7. 《UnityAPI.Network网络》(Yanlz+Unity+SteamVR+云技术+5G+AI+VR云游戏+Network+isClient+Connect+Server+立钻哥哥++OK++)

    <UnityAPI.Network网络> 版本 作者 参与者 完成日期 备注 UnityAPI_Network_V01_1.0 严立钻 2020.06.16 #<UnityAPI.N ...

  8. Network protocols

    2019独角兽企业重金招聘Python工程师标准>>> The network stack does serveral seemingly-impossible things. It ...

  9. 网络错误修复工具:Network Fault Repair Tool Build20160414

    网络错误修复工具:Network Fault Repair Tool Build20160414 1 ::请勿轻易修改此文件,以避免不可预知的错误 gwsbhqt@163.com 2 3 @echo ...

最新文章

  1. 展望2009,回眸2008
  2. 一文搞定cookie,session,token
  3. [2018-08-03] python开发个人资源共享网--第一天
  4. 关于IIS 7.0 局域网无法访问的解决方法 windows7 iis局域网不能访问
  5. 如何解决SVN Commit failed (details follow): Access denied
  6. 数据挖掘学习日志(part2)--主成分法确定权重与R实现
  7. 【转】伪静态URLRewrite学习笔记
  8. DevExpress v17.2新版亮点—WinForms篇(四)
  9. REVERSE-PRACTICE-CTFSHOW-6
  10. n个整数,其中有两个数是重复的,要求找出这两个重复的整数
  11. 消息队列(1):一个消息队列应该有的特点
  12. 超松弛迭代法解线性方程组c语言,超松弛迭代法解线性方程组.doc
  13. SSR -- 服务端渲染基础
  14. whoosh mysql_使用WhooshAlchemy报错'function' object has no attribute 'config'
  15. lsof 命令实用用法介绍
  16. 计算机网络————P1 概念、组成、功能和分类
  17. python 最优解 ma_python遗传算法求最优解
  18. win7电脑便签怎么弄
  19. 解析博图数据块(昆仑通态触摸屏自动命名)
  20. 支付宝微信QQ钱包收款码合并教程及源码下载

热门文章

  1. linux mint cinnamon崩溃,正在运行后备 模式,linux mint 崩溃
  2. C语言学习——运算符详解
  3. 传奇3怎么查询账号所在服务器,传奇3登录过程分析 -电脑资料
  4. Google,Verizon和网络中立性辩论
  5. 计算机组成原理之(2)计算机的运算方法
  6. 2008中国之殇(转)
  7. 小白怎么区别插画和原画?插画和原画又有哪些差异?
  8. 游戏原画和商业插画哪个更难一点,学哪个好?
  9. 关于病毒防疫必须知道的英文
  10. Spring Boot 2.6 发布了和一些重要变更