[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 ...
随机推荐
- SpringMVC配置web.xml文件详解(列举常用的配置)
常用的web.xml的配置 1.Spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在web.xml配置监听器ContextLo ...
- 浅析 GlusterFS 与 JuiceFS 的架构异同
在进行分布式文件存储解决方案的选型时,GlusterFS 无疑是一个不可忽视的考虑对象.作为一款开源的软件定义分布式存储解决方案,GlusterFS 能够在单个集群中支持高达 PiB 级别的数据存储. ...
- 文心一言(ERNIE Bot)初体验
引言 几个月前向百度提交了文心一言的体验申请,这两天收到了可以体验的通知,立马体验了一把.总体来说,文心一言基本上能做到有问必答,但是一些奇葩的问题还是会难住这位初出茅庐的 AI. 分享体验 我先后问 ...
- ViTPose+:迈向通用身体姿态估计的视觉Transformer基础模型
身体姿态估计旨在识别出给定图像中人或者动物实例身体的关键点,除了典型的身体骨骼关键点,还可以包括手.脚.脸部等关键点,是计算机视觉领域的基本任务之一.目前,视觉transformer已经在识别.检测. ...
- Mysql基础篇-查询、函数、多表、事务
1. 基础篇 1.1 mysql用户和权限管理 查询用户 USER mysql; SELECT * FROM user; 创建用户 CREATE USER '用户名'@'主机名' IDENTIFIED ...
- k8s 自动扩缩容HPA原理及adapter配置详解👑
大家好,我是蓝胖子,都知道,k8s拥有自动扩缩容机制HPA,我们能够通过配置针对不同的扩缩容场景进行自动扩缩容,往往初学者在面对其中繁多配置的时候会学了又忘记,今天我将会以一种不同的视角,结合api ...
- 算法打卡|Day4 链表part02
Day4 链表part02 今日任务 ● 24. 两两交换链表中的节点 ● 19.删除链表的倒数第N个节点 ● 面试题 02.07. 链表相交 ● 142.环形链表II 目录 Day4 链表part0 ...
- 校招零Offer要不要先找实习?
国庆前后被问到最多的问题是:"磊哥,我现在还是 0 Offer,要不要先去找个实习?",给大家看看部分截图. 同学 A: 同学 B: 同学 C: 其他还有一些截图,我这里就不一一贴 ...
- Jmeter-变量的嵌套使用
场景: 有存在获取到多个登录账号,循环获取单个变量的情况. 常用方法: ${__BeanShell(vars.get("变量字段_${变量字段}"))} 取值示例: 思维扩展: 一 ...
- 基于GPS定位和人脸识别的作业识别管理系统
一.技术参数 mysql5.5 asp.net jquery 高德地图api 百度人脸识别api 二.功能简介 实现简单的施工项目管理,包括项目地点,工期,名称,编号等 实现作业人员的档案信息管理,包 ...