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. 微服务集成redis并通过redis实现排行榜的功能

    默认你已经看过我之前的教程了,并且拥有上个教程完成的项目, 之前的教程 https://www.cnblogs.com/leafstar/p/17638933.html 由于redis的安装网上教程很 ...

  2. 【pandas小技巧】--DataFrame的显示样式

    上一篇介绍了DataFrame的显示参数,主要是对DataFrame中值进行调整. 本篇介绍DataFrame的显示样式的调整,显示样式主要是对表格本身的调整,比如颜色,通过颜色可以突出显示重要的值, ...

  3. datetime获取当前日期前十二个月份

    from dateutil.parser import parse from dateutil.relativedelta import relativedelta # 当前日期前十二个月 time_ ...

  4. jQuery提交表单

    $('#myform').form('submit',{ url: "login.action", onSubmit:function(){ return $('#myform') ...

  5. 如何使用Vite创建Vue3的uniapp项目

    项目结构 my-vue3-project ├─ .env //默认环境变量 ├─ .env.development //开发环境变量 ├─ .eslintrc-auto-import.json //( ...

  6. # 简明快速配置 Rust 工具链

    以下内容为本人的学习笔记,如需要转载,请声明原文链接微信公众号「ENG八戒」https://mp.weixin.qq.com/s/dBzL9WZ8P1L1X9j_XkmNQg 你可能会为不同版本的工具 ...

  7. Solution -「ARC 123F」Insert Addition

    大约是翻译了一下官方题解? @Description@ 对于一个整数序列 \(P=(P_{1},\dots,P_{m})\),定义 \(f(P)\) 为一个序列 \(Q\) 满足: \(Q_{i}=P ...

  8. Vue 搭配 Spring MVC 创建一个 web 项目

    Vue 搭配 Spring MVC 创建一个 web 项目 想要写一个登录的web应用程序.页面使用Vue,后端使用Spring MVC,最终打成war包,放在tomcat下启动. 1.创建Sprin ...

  9. 人工智能AI绘画全攻略(AI绘画教程分享)

    在过去的三个月一直在研究人工智能生成绘画这个方向,3 月份的时候参加了小红书的小航海,也因为这个方向的选择正好对应到了趋势,小红书在一个半月做到了 1 万粉.我为什么看好这个方向? 主要是从三个方面: ...

  10. 在macOS上,可以使用以下步骤来清理本地多个版本的Python:

    确认已经安装了Homebrew 如果您还没有安装Homebrew,可以在终端中运行以下命令进行安装: /bin/bash -c "$(curl -fsSL https://raw.githu ...