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)的更多相关文章

  1. HBase官方文档

    HBase官方文档 目录 序 1. 入门 1.1. 介绍 1.2. 快速开始 2. Apache HBase (TM)配置 2.1. 基础条件 2.2. HBase 运行模式: 独立和分布式 2.3. ...

  2. Triangle 解答

    Question Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...

  3. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. [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, ...

  5. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  6. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  7. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  8. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  9. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

  10. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

随机推荐

  1. Go 语言中排序的 3 种方法

    原文链接: Go 语言中排序的 3 种方法 在写代码过程中,排序是经常会遇到的需求,本文会介绍三种常用的方法. 废话不多说,下面正文开始. 使用标准库 根据场景直接使用标准库中的方法,比如: sort ...

  2. ORM分组查询复杂查询

    记录一下自己在工作中遇到的一个问题,就是根据一个字段分类,然后还要统计这个字段不同状态的数量,这里我举个例子 假如有好多学生,这些学生来自不同的班级,现在我们要统计每一个班级中男生和女生的数量 def ...

  3. Codeforces Round #576 (Div. 2)

    A - City Day 题意:给n,x,y和数组a[n],求最小的下标d,使得有a[d-x,d-x+1,--d-1,d+1,d-1,d+1,--d+y-1,d+y]都比a[d]小,若d-x<= ...

  4. Mybatis自动生成mapper和实体类

    准备工作:需要俩个jar包: (1)连接数据库的jar包:mysql-connector-java-5.1.16-bin.jar (2)实现需求的插件Generator:mybatis-generat ...

  5. dedebiz实时时间调用

    {dede:tagname runphp='yes'}@me = date("Y-m-d H:i:s", time());{/dede:tagname}

  6. 2023 ICPC 网络赛 II

    开场顺着读了 AC 不会,B 是 KDT 优化建图板子,让 zsy 确认了一下并制止他现在做.把 D 转化转化成了经典问题·,当时以为是网络流,所以 zsy 签完 M 就上去写了,写一半发现假了,问了 ...

  7. GO数组解密:从基础到高阶全解

    在本文中,我们深入探讨了Go语言中数组的各个方面.从基础概念.常规操作,到高级技巧和特殊操作,我们通过清晰的解释和具体的Go代码示例为读者提供了全面的指南.无论您是初学者还是经验丰富的开发者,这篇文章 ...

  8. android 中service的简单事例

    源码 public class ServiceDemoActivity extends Activity { private static final String TAG = "Servi ...

  9. Go通道机制与应用详解

    本文深入探讨了Go语言中通道(Channel)的各个方面,从基础概念到高级应用.文章详细解析了通道的类型.操作方法以及垃圾回收机制,更进一步通过具体代码示例展示了通道在数据流处理.任务调度和状态监控等 ...

  10. C#学习笔记--面向对象三大特征

    C#核心 面向对象--封装 用程序来抽象现实世界,(万物皆对象)来编程实现功能. 三大特性:封装.继承.多态. 类与对象 声明位置:namespace中 样式:class 类名{} 命名:帕斯卡命名法 ...