当前位置:网站首页>【小码匠自习室】朋友的朋友不是朋友
【小码匠自习室】朋友的朋友不是朋友
2022-08-08 13:53:00 【小码匠】
标签
- 图、无向图
题目地址
Q4. 友達の友達
- https://algo-method.com/tasks/413
問題描述
输入
输出
输出结果
输入示例 1
6 7 0
0 1
0 5
1 3
1 5
2 3
3 4
4 5
输入示例 1
2
六种朋友的关系如下面的图。
阿尔勒的朋友是学生 1 和学生 5,阿尔勒的朋友的朋友是学生 3 和学生 4。由于 阿尔勒 有两个“朋友的朋友”,我们将输出 2。
输入示例 2
5 7 2
0 2
0 3
1 2
1 4
2 3
2 4
3 4
输出示例 2
0
阿尔勒和学校所有学生都是朋友,所以朋友的朋友为:0
题解
小码匠题解
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
void coder_solution();
int main() {
// 小码匠
coder_solution();
// 返回
return 0;
}
void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, x, a, b;
cin >> n >> m >> x;
vector<vector<int>> c(n);
for(int i = 0; i < m; ++i) {
cin >> a >> b;
c[a].push_back(b);
c[b].push_back(a);
}
unordered_set<int> ans;
set<int> f;
for(auto i : c[x]) {
f.insert(i);
}
for(auto i : c[x]) {
for (auto j : c[i]) {
if (!f.count(j) && j != x) {
ans.insert(j);
}
}
}
cout << ans.size();
}
边栏推荐
- 接口测试,
- Qt操作Sqlite类封装,及命令行导入csv文件到Sqlite数据库
- 看到这个应用上下线方式,不禁感叹:优雅,太优雅了!
- poj2096 Collecting Bugs
- KD-SCFNet:通过知识蒸馏实现更准确、更高效的显着目标检测(ECCV2022)
- flutter 身兼数职的getx —— 简介
- Flink1.15 组件RPC通信过程概览图
- 又一个千亿市场,冰淇淋也成了创新试验田
- R语言patchwork包将多个ggplot2可视化结果组合起来、使用plot_annotation函数以及tag_level参数为组合图添加自定义编码序列(字符向量列表)
- 【Personal Summary】2022.8.7 Week End
猜你喜欢
随机推荐
Review: What is the pre-approval of autumn recruitment?What is an ordinary autumn move?It's all recruitment, why do you need to set these two recruitment time periods?
flutter 身兼数职的getx —— 简介
医学图像数据增强-归一化
webgl 基础
Full of dry goods, Yu Jingxin class of the Institute of Information Technology, Chinese Academy of Sciences will help you get academic research and thesis writing skills
R语言patchwork包将多个ggplot2可视化结果组合起来、使用plot_annotation函数以及tag_level参数为组合图添加自定义编码序列(字符向量列表)
QWebAssembly中文适配
更改默认打开应用程序设置
「复盘」面试BAMT回来整理398道高频面试题,助你拿高薪offer
暗恋云匹配匿名交友聊天系统开发
Code Casual Recording Notes_Dynamic Programming_322 Change Exchange
idea中项目呈现树形结构
HackTheBox | Horizontall
浅学一下二叉树链式存储结构的遍历
从零开始,如何拥有自己的博客网站【华为云至简致远】
HackTheBox | Horizontall
Ingress:比Service更强大的服务暴露与负载均衡
Flink1.15源码阅读——StreamGraph流图
Knowledge points and written test questions related to shift operations, bit operations, and logical operations
专访|360高瀚昭:ISC十年,360数字安全大脑能够“看见”什么?