[ABC262B] Triangle (Easier)
Problem Statement
You are given a simple undirected graph with $N$ vertices and $M$ edges. The vertices are numbered $1, \dots, N$, and the $i$-th $(1 \leq i \leq M)$ edge connects Vertex $U_i$ and Vertex $V_i$.
Find the number of tuples of integers $a, b, c$ that satisfy all of the following conditions:
- $1 \leq a \lt b \lt c \leq N$
- There is an edge connecting Vertex $a$ and Vertex $b$.
- There is an edge connecting Vertex $b$ and Vertex $c$.
- There is an edge connecting Vertex $c$ and Vertex $a$.
Constraints
- $3 \leq N \leq 100$
- $1 \leq M \leq \frac{N(N - 1)}{2}$
- $1 \leq U_i \lt V_i \leq N \, (1 \leq i \leq M)$
- $(U_i, V_i) \neq (U_j, V_j) \, (i \neq j)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $M$
$U_1$ $V_1$
$\vdots$
$U_M$ $V_M$
Output
Print the answer.
Sample Input 1
5 6
1 5
4 5
2 3
1 4
3 5
2 5
Sample Output 1
2
$(a, b, c) = (1, 4, 5), (2, 3, 5)$ satisfy the conditions.
Sample Input 2
3 1
1 2
Sample Output 2
0
Sample Input 3
7 10
1 7
5 7
2 5
3 6
4 7
1 5
2 4
1 3
1 6
2 7
用邻接矩阵存边,暴力枚举三个数,用邻接矩阵判断他们是否成三元环。
#include<cstdio>
const int N=105;
int n,m,u,v,e[N][N],cnt;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
e[u][v]=e[v][u]=1;
}
for(int i=1;i<n;i++)
for(int j=i+1;j<n;j++)
for(int k=j+1;k<=n;k++)
if(e[i][j]&&e[j][k]&&e[i][k])
++cnt;
printf("%d",cnt);
}
[ABC262B] Triangle (Easier)的更多相关文章
- HBase官方文档
HBase官方文档 目录 序 1. 入门 1.1. 介绍 1.2. 快速开始 2. Apache HBase (TM)配置 2.1. 基础条件 2.2. HBase 运行模式: 独立和分布式 2.3. ...
- Triangle 解答
Question Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- 文心一言 VS 讯飞星火 VS chatgpt (80)-- 算法导论7.4 5题
五.如果用go语言,当输入数据已经"几乎有序"时,插入排序速度很快.在实际应用中,我们可以利用这一特点来提高快速排序的速度.当对一个长度小于 k 的子数组调用快速排序时,让它不做任 ...
- .NET周刊【8月第4期 2023-08-27】
国内文章 AgileConfig-1.7.0 发布,支持 SSO https://www.cnblogs.com/kklldog/p/agileconfig-170.html AgileConfig ...
- PDF 补丁丁 1.0 正式版
经过了一年多的测试和完善,PDF 补丁丁发布第一个开放源代码的正式版本了. PDF 补丁丁也是国内首先开放源代码.带有修改和阅读PDF的功能的 PDF 处理程序之一. 源代码网址:https://gi ...
- 蚂蚁集团混沌工程 ChaosMeta V0.5 版本发布
混沌工程 ChaosMeta 的全新版本 V0.5 现已正式发布!该版本包含了许多新特性和增强功能,为用户提供了支撑混沌工程各个阶段的平台能力,以及降低使用门槛的用户界面. ChaosMeta V0. ...
- iOS交叉编译
编译objc程序 ~/toolchain4/pre/bin/arm-apple-darwin9-gcc -arch arm -lobjc -framework CoreFoundation -fram ...
- vue中watch侦听器,deep和immediate的用法
1.deep深度监听的用法 当监听一个对象时,可能想监听整个对象的变化,而不仅仅是某个属性.但在默认情况下,如果你正在监听formData对象并且修改了formData.username,对应的侦听器 ...
- LeetCode 周赛上分之旅 #48 一道简单的树上动态规划问题
️ 本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 和 BaguTree Pro 知识星球提问. 学习数据结构与算法的关键在于掌握问题背后的算法思维框架,你的思考越 ...
- 下载、安装CAN-EYE植被参数工具
本文介绍植被指数计算软件CAN-EYE的下载.安装方法. CAN-EYE软件是由法国国家农业研究院(French National Institute of Agricultural Rese ...
- 毕业三年,月薪30K,我想跟你聊聊!
大家好,我是冰河~~ 很多读者私信问我,自己工作三年多了,随着工作年限的不断增长,感觉自己的技术水平与自己的工作年限严重不符.想跳槽出去换个新环境吧,又感觉自己的能力达不到心仪公司的标准,即使投了简历 ...
- Unity - EditorWindow 折叠树显示(IMGUI)
仅适用于2018之前的版本,有UIElements或者UIWidgets的最好用新的 基本实现 树节点 public interface ITreeNode { ITreeNode Parent { ...