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:

  1. $N$ $M$
  2. $U_1$ $V_1$
  3. $\vdots$
  4. $U_M$ $V_M$

Output

Print the answer.


Sample Input 1

  1. 5 6
  2. 1 5
  3. 4 5
  4. 2 3
  5. 1 4
  6. 3 5
  7. 2 5

Sample Output 1

  1. 2

$(a, b, c) = (1, 4, 5), (2, 3, 5)$ satisfy the conditions.


Sample Input 2

  1. 3 1
  2. 1 2

Sample Output 2

  1. 0

Sample Input 3

  1. 7 10
  2. 1 7
  3. 5 7
  4. 2 5
  5. 3 6
  6. 4 7
  7. 1 5
  8. 2 4
  9. 1 3
  10. 1 6
  11. 2 7

用邻接矩阵存边,暴力枚举三个数,用邻接矩阵判断他们是否成三元环。

  1. #include<cstdio>
  2. const int N=105;
  3. int n,m,u,v,e[N][N],cnt;
  4. int main()
  5. {
  6. scanf("%d%d",&n,&m);
  7. for(int i=1;i<=m;i++)
  8. {
  9. scanf("%d%d",&u,&v);
  10. e[u][v]=e[v][u]=1;
  11. }
  12. for(int i=1;i<n;i++)
  13. for(int j=i+1;j<n;j++)
  14. for(int k=j+1;k<=n;k++)
  15. if(e[i][j]&&e[j][k]&&e[i][k])
  16. ++cnt;
  17. printf("%d",cnt);
  18. }

[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. ETL之apache hop系列2-hop web安装和入门

    前言 在Docker安装apache hop 首先确保Docker已经安装和运行Java 11 JDK 安装文档参考:https://blog.csdn.net/Chia_Hung_Yeh/artic ...

  2. 如何获取和分析Java堆信息

    引言 在Java应用程序的开发和维护过程中,了解和分析Java堆信息是一项重要的任务.本文将介绍如何获取Java堆信息的不同方法,并提供一些分析堆信息的实用技巧. 获取Java堆信息的方法 Java虚 ...

  3. CodeForces 1324F Maximum White Subtree

    题意 给定一棵\(n\)个节点的无根树,每个节点为黑色或者白色,每个点的答案为包含该点的子树(指无根子树)的白色节点数减黑色节点数的最大值 分析 对于无根树的题一般指定某一个点为根,不妨设为\(1\) ...

  4. 【项目源码】JavaWeb网上购书系统

    JavaWeb网上购书系统 介绍 采用JSP.Servlet.MySQL.Tomcat8.0开发的网上购书系统. 软件架构 网上书城主要功能如下: (1) 前台(客户购买)部分: ① 用户管理:注册会 ...

  5. 【爬虫实战】用python爬豆瓣电影《热烈》短评

    目录 一.爬虫对象-豆瓣电影短评 二.爬取结果 三.爬虫代码讲解 三.演示视频 四.获取完整源码 一.爬虫对象-豆瓣电影短评 您好!我是@马哥python说,一名10年程序猿. 今天分享一期爬虫案例, ...

  6. .Net8 AOT+VMP简单的逆向分析

    1.前言 测试下VMP加密.NET的强度,选了最新的.Net8+AOT编译,用VMP给它加壳.最后逆向下,简单的分析,本篇看下. 2.概述 一.前奏 首先一段简单的C#代码: namespace Te ...

  7. Kafka Stream 处理器API

    6.1章节内容 了解如何使用处理器API对以下场景进行处理 ①以有规律的间隔定期执行 ②将控制记录如何向下游发送 ③将记录转发给特定的子节点 ④创建Kafka Streams API中不存在的功能 6 ...

  8. Solution -「洛谷 P5610」「YunoOI 2013」大学

    Description Link. 区间查 \(x\) 的倍数并除掉,区间查和. Solution 平衡树. 首先有个基本的想法就是按 \(a_{i}\) 开平衡树,即对于每个 \(a_{i}\) 都 ...

  9. 使用mtrace追踪JVM堆外内存泄露

    原创:扣钉日记(微信公众号ID:codelogs),欢迎分享,非公众号转载保留此声明. 简介 在上篇文章中,介绍了使用tcmalloc或jemalloc定位native内存泄露的方法,但使用这个方法相 ...

  10. Vitess全局唯一ID生成的实现方案

    为了标识一段数据,通常我们会为其指定一个唯一id,比如利用MySQL数据库中的自增主键. 但是当数据量非常大时,仅靠数据库的自增主键是远远不够的,并且对于分布式数据库只依赖MySQL的自增id无法满足 ...