题意:

输入两个正整数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. 题解 SP8284 WEIGHT - Weighted Sum

    SP8284 WEIGHT - Weighted Sum 题意描述 给出长度为n(n<=1e6)的序列A, A中元素可能为正数,可为负数或0,.让你构造一个长度为n的序列W,给这些整数A赋权,使 ...

  2. 深入delphi编程理解之消息(一)WINDOWS原生窗口编写及消息处理过程

    通过以sdk方式编制windows窗口程序,对理解windows消息驱动机制和delphi消息编程有很大的帮助. sdk编制windows窗口程序的步骤: 1.对TWndClass对象进行赋值; 2. ...

  3. txt文件太大打不开怎么办

    #开始 最近在调试代码的时候,生成了一个400MB的日志文件 找了很多文本编辑器,都表示太大了打不开 QAQ #解决方案 百度下载 “txt杀手” 用这个软件把文本文件拆分成小份就可以打开了 输入如图 ...

  4. 使用Eclipse工具开发Servlet(新建web项目->创建Servlet->部署和访问Servlet)

    在Eclipse工具栏中的[File]->[New]->[Other],打开如下菜单栏,选择Dynamic Web Project 点击下一步,如下图所示: 这里Dynamic web m ...

  5. 点击<a href="#">阻止自动跳转到顶部方法

    最近开发web项目,遇到一个问题 ,就是在<a>标签加href="#",并增加onclick事件,页面会自动在点击该标签绑定的元素时,自动跳转到页面顶部,在网上寻求了一 ...

  6. Qt应用程序的打包

    Windows系统下打包: qt用realse版本编译然后打包发行 debug编译后的文件比realse版本大很多先在编译好的debug或者realse执行程序的目录下将执行该城西对应的所有dell文 ...

  7. 一个含有Zeta函数的级数

    \[\Large\sum_{k=1}^{\infty}\frac{(2^{2k-1}-2)(4^{2k+1}-3^{2k+1})}{144^k\,k\,(2k+1)}\zeta(2k)\] \(\La ...

  8. XCOJ 1008: 级数求和

    1008: 级数求和 题目描述 已知:Sn= 1+1/2+1/3+…+1/n.显然对于任意一个整数K,当n足够大的时候,Sn大于K.现给出一个整数K(1<=k<=15),要求计算出一个最小 ...

  9. query_phase_execution_exception

    ES报错信息: { "error": { "root_cause": [ { "type": "query_phase_execu ...

  10. ajax发送GET和POST请求

    1.ajax-get请求demo <script> document.getElementById("buttonname").onclik=function(){ / ...