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. mall:redis项目源码解析

    目录 一.mall开源项目 1.1 来源 1.2 项目转移 1.3 项目克隆 二.Redis 非关系型数据库 2.1 Redis简介 2.2 分布式后端项目的使用流程 2.3 分布式后端项目的使用场景 ...

  2. 银河麒麟SP2 auditd服务内存泄露问题

    这几天遇到基于海光服务器的银河麒麟V10 SP2版本操作系统出现内存无故增长问题. 排查发现auditd服务,占用了大量内存. 我的环境是银河麒麟V10 SP2 524,audit版本audit-3. ...

  3. 如何对MongoDB进行测试

    一.环境搭建 关于环境搭建,最好的搭建方式,当然是脚本一键式搭建 我这里是centos6 x64版本的linux上进行构建,这个linux版本现在应该是大部分的主流服务器的标配版本 下面是安装脚本的编 ...

  4. 第2章 Git安装

    兄弟,恭喜你,刷到这篇超详细安装GIt教程,就让Codeyang带你一步一步的安装Git!~~ Git官网地址: https://git-scm.com/ 查看 GNU 协议,可以直接点击下一步. 选 ...

  5. Note -「普通生成函数 OGF」

    \(\mathbf{OGF}\) 的定义 对于一个序列 \(a_{1},a_{2},\cdots\),我们称: \[G(x)=\sum_{i=0}^{\infty}a_{i}x^{i} \] 为序列 ...

  6. 使用Triton部署chatglm2-6b模型

    一.技术介绍 NVIDIA Triton Inference Server是一个针对CPU和GPU进行优化的云端和推理的解决方案. 支持的模型类型包括TensorRT.TensorFlow.PyTor ...

  7. destoon9.0游戏自媒体类型综合资讯门户模板

    随着时代发展,自媒体资讯适合当前的互联网情形.呕心沥血开发的一套自媒体综合门户网站模板,本模板采用纯手写开发,带会员中心.首页,列表页,内容页,搜索页面精心编写,非常大气,并配移动端.注意:模板目前只 ...

  8. tensorboard可视化点云

    tensorboard可视化点云 用 tensorboard 自带的 add_mesh 方法:支持可视化点云和网格,参考链接: tensorflow 网站的tensorboard pytorch 网站 ...

  9. 圆柱坐标系(Cylindrical Coordinate System)

    参考:维基百科 圆柱坐标系(英语:cylindrical coordinate system)是一种三维坐标系统.它是二维极坐标系往 z-轴的延伸.添加的第三个坐标 \(z\) 专门用来表示 P 点离 ...

  10. P9140 [THUPC 2023 初赛] 背包

    prologue 这很难评(调了我 1h,我都想紫砂了. 还是典型得不重构就看不见系列. analysis 如果我们还是一个正常人,那么我们大体上是能看到题目的加粗字,这个格式很明显符合我们的同余最短 ...