当前位置:网站首页>【小码匠自习室】朋友的朋友不是朋友
【小码匠自习室】朋友的朋友不是朋友
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();
}
边栏推荐
- QtWebassembly遇到的一些报错问题及解决方案
- KMP Media Group South Africa implemented a DMS (Document Management System) to digitize the process, employees can again focus on their actual tasks, providing efficiency
- Tensorflow与Keras进行机器学习、深度学习
- 【Redis】位图以及位图的使用场景(统计在线人数和用户在线状态)
- 暗恋云匹配匿名交友聊天系统开发
- Verilog HDL Bits training 09 grammar foundation
- IT故障快速解决就用行云管家!快速安全!
- 删库不易,跑路更难
- 【索引】图神经论文之GCN(持更)
- 6. [opencv mouse callback event]
猜你喜欢

sample function—R language

TS+Hooks二次封装antd Modal,实现可拖拽

OpenInfra Days China 2022 |StreamNative 翟佳、刘德志受邀分享

用 Antlr 重构脚本解释器

“自降估值”3个亿的咖啡独角兽要IPO了

难产的“第一股”:中式快餐之困

专访|360高瀚昭:ISC十年,360数字安全大脑能够“看见”什么?

MySQL:索引(1)原理与底层结构

【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...

哈佛大学砸场子:DALL-E 2只是「粘合怪」,生成正确率只有22%
随机推荐
【os.path】的相关用法(持更)
serialize serialize native method
idea增加左右箭头
【Rust—LeetCode题解】1408.数组中的字符串匹配
Thesis understanding: "Self-adaptive loss balanced Physics-informed neural networks"
Qt 在循环中超时跳出
什么样的程序员在35岁依然被公司抢着要?打破程序员“中年危机”
Harvard University smashes the field: DALL-E 2 is just a "glue monster", and the generation accuracy rate is only 22%
【第2天】SQL快速入门-条件查询(SQL 小虚竹)
如何对用户输入进行校验
京东三面惨遭被虐,关于redis,高并发,分布式,问懵了
itk中图像2d-3d配准整理
删库不易,跑路更难
更改C盘用户目录下的用户名(亲测有效)
win32&mfc————win32菜单栏&库
代码随想录笔记_动态规划_322零钱兑换
一桩事先张扬的网红书店倒闭案
难产的“第一股”:中式快餐之困
Implement a customized pin code input control
干货满满,中科院信工所于静新课帮你get学术研究与论文写作技能