题意:

输入两个正整数N和K(<=1000),接下来输入N行数据,每行包括两个人由三个大写字母组成的ID,以及两人通话的时间。输出团伙的个数(相互间通过电话的人数>=3),以及按照字典序输出团伙老大的ID和团伙的人数(团伙中通话时长最长的人视为老大,数据保证一个团伙仅有一名老大)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s,s2;
int x[],y[];
vector<pair<int,int> >edge[];
bool vis[];
int val[];
int mx=;
int pos=;
int ans[];
int num[];
int cnt=;
int c[];
bool visedge[];
int sum2=;
void dfs(int x){
if(!vis[x])
++cnt;
vis[x]=;
for(auto it:edge[x]){
if(visedge[it.second])
continue;
visedge[it.second]=;
if(!vis[it.first]){
++cnt;
vis[it.first]=;
}
val[x]+=c[it.second];
val[it.first]+=c[it.second];
sum2+=c[it.second];
if(val[x]>mx){
mx=val[x];
pos=x;
}
dfs(it.first);
}
}
int main(){
int n,k;
cin>>n>>k;
for(int i=;i<=n;++i){
cin>>s>>s2>>c[i];
x[i]=(s[]-'A')**+(s[]-'A')*+s[]-'A';
y[i]=(s2[]-'A')**+(s2[]-'A')*+s2[]-'A';
edge[x[i]].push_back({y[i],i});
edge[y[i]].push_back({x[i],i});
}
int sum=;
for(int i=;i<=n;++i){
sum2=;
mx=;
pos=;
cnt=;
if(!vis[x[i]])
dfs(x[i]);
if(cnt>&&sum2>k){
ans[pos]=sum2;
num[pos]=cnt;
++sum;
}
}
cout<<sum<<"\n";
for(int i=;i<**;++i)
if(ans[i]){
char alp[];
int tmp=i;
alp[]=tmp//;
tmp%=*;
alp[]=tmp/;
tmp%=;
alp[]=tmp;
for(int j=;j<=;++j){
alp[j]+='A';
cout<<alp[j];
}
cout<<" "<<num[i]<<"\n";
}
return ;
}

【PAT甲级】1034 Head of a Gang (30 分)的更多相关文章

  1. PAT 甲级 1034 Head of a Gang (30 分)(bfs,map,强连通)

    1034 Head of a Gang (30 分)   One way that the police finds the head of a gang is to check people's p ...

  2. pat 甲级 1034. Head of a Gang (30)

    1034. Head of a Gang (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One wa ...

  3. PAT甲级1034. Head of a Gang

    PAT甲级1034. Head of a Gang 题意: 警方找到一个帮派的头的一种方式是检查人民的电话.如果A和B之间有电话,我们说A和B是相关的.关系的权重被定义为两人之间所有电话的总时间长度. ...

  4. pat 甲级 1034 ( Head of a Gang )

    1034 Head of a Gang (30 分) One way that the police finds the head of a gang is to check people's pho ...

  5. PAT 甲级 1064 Complete Binary Search Tree (30 分)(不会做,重点复习,模拟中序遍历)

    1064 Complete Binary Search Tree (30 分)   A Binary Search Tree (BST) is recursively defined as a bin ...

  6. PAT 甲级 1053 Path of Equal Weight (30 分)(dfs,vector内元素排序,有一小坑点)

    1053 Path of Equal Weight (30 分)   Given a non-empty tree with root R, and with weight W​i​​ assigne ...

  7. PAT 甲级 1038 Recover the Smallest Number (30 分)(思维题,贪心)

    1038 Recover the Smallest Number (30 分)   Given a collection of number segments, you are supposed to ...

  8. PAT Advanced 1034 Head of a Gang (30) [图的遍历,BFS,DFS,并查集]

    题目 One way that the police finds the head of a gang is to check people's phone calls. If there is a ...

  9. PAT甲级1034 Head of a Gang【bfs】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624 题意: 给定n条记录(注意不是n个人的 ...

随机推荐

  1. 利用ZotFile对Zotero中的文献进行整理

    1.安装ZotFile插件 *** 以后补充 *** 2.配置ZotFile 配置 3.整理操作 (1)将文件拖进Zotero软件相应的目录(自己创建) (2)查看文件位置 (未整理之前) (3)整理 ...

  2. 修改链接服务器 Rpc &Rpc Out

    USE [master] GO EXEC master.dbo.sp_serveroption @server=N'LinkName', @optname=N'rpc', @optvalue=N'tr ...

  3. strtok() and strtod()

    1.strtok(参数1,参数2)按指定的分割符将字符串分割开来 参数1:表示要被分割的字符串的地址: 参数2:表示指定的分割符的地址: 例如:按空格分割“Hello World” buffer[] ...

  4. 【PAT甲级】1084 Broken Keyboard (20 分)

    题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...

  5. 运维数据同步工具:rsync,serync,csync,drbd,info(基于文件系统)

     Rsync官方站点:http://rsync.samba.org 1. Rsync rsync是一款开源的实现数据全量与增量同步备份的工具 生产环境中使用的场景: 1:一般用于数据异地备份 2:用于 ...

  6. FYF的煎饼果子

    利用等差数列公式就行了,可以考虑特判一下m >= n($ m, n \neq 1 $),这时一定输出“AIYAMAYA”. #include <iostream> using nam ...

  7. php引入html页面 css报错 404

    php引入html页面 css报错 404, html页面内 有css, 有一样 是这么写的 结果就报错了, 原来是 -moz这一句,在这句前面随便加一句别的样式就可以....

  8. canvas的beginPath和closePath

    https://www.cnblogs.com/xuehaoyue/p/6549682.html https://segmentfault.com/a/1190000010330319 https:/ ...

  9. springboot学习4使用日志:logback

    springboot学习4使用日志:logback 一.基本知识说明 SpringBoot默认使用logback作为日志框架 ,所以引入起步依赖后就可以直接使用logback,不需要其他依赖. Spr ...

  10. Windows 搭建WAMP+Mantis

    下载WAMP http://www.wampserver.com/ 安装直接下一步就行 安装完启动后,显示下面的logo 在浏览器输入 127.0.0.1/phpmyadmin    设置数据库(默认 ...