[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 ...
随机推荐
- VScode软件的安装以及C/C++环境配置的方法
今天和大家分享一下VScode软件的安装以及C/C++环境配置的方法.手把手教大家入门. 1,下载VScode编译器 (1) 官网下载链接:https://code.visualstudio.c ...
- 【JMeter】使用BeanShell写入内容到文件
使用BeanShell写入内容到文件 目录 使用BeanShell写入内容到文件 一.前言 二.提取 三.写入 一.前言 在我们日常工作中,可能会遇到需要将请求返回的数据写入到文件中.在我们使用J ...
- Go 并发编程 - Goroutine 基础 (一)
基础概念 进程与线程 进程是一次程序在操作系统执行的过程,需要消耗一定的CPU.时间.内存.IO等.每个进程都拥有着独立的内存空间和系统资源.进程之间的内存是不共享的.通常需要使用 IPC 机制进行数 ...
- 《Linux基础》05. 定时任务调度 · 磁盘分区与挂载 · 网络配置
@ 目录 1:定时任务调度 1.1:crontab 1.2:at 2:磁盘分区与挂载 2.1:原理介绍 2.2:硬盘说明 2.3:磁盘目录情况查询 2.3.1:lsblk 2.3.2:df 2.3.3 ...
- CodeForces 1311E Construct the Binary Tree
题意 给定\(n\)和\(d\),构造一颗\(n\)个节点的二叉树(以\(1\)为根),所有节点到\(1\)的距离和为\(d\),不行输出\(NO\),否则输出\(YES\)和\(2\)-\(n\)的 ...
- Google Hacking语法总结
Google Hacking语法总结 Google Hacking是利用谷歌搜索的强大,来在浩瀚的互联网中搜索到我们需要的信息.轻量级的搜索可以搜素出一些遗留后门,不想被发现的后台入口,中量级的搜索出 ...
- Django框架——路由控制、视图层
文章目录 1 路由控制 一 Django中路由的作用 二 简单的路由配置 三 有名分组 四 路由分发 五 反向解析 六 名称空间 七 django2.0版的path 基本示例 path转化器 注册自定 ...
- xgo多线程
import threading import time #导入xgoedu from xgoedu import XGOEDU from xgolib import XGO #导入xgolib # ...
- win11系统无法解决的死结
如果需要使用网上银行.win11一定不能使用. win11已经取消了,对于IE浏览器的支持和安装. 但是大部分网银都是要求IE浏览器.或者IE内核.实际过程当中.虽然所有的浏览器都说兼容IE有IE内核 ...
- virsh domxxx命令
1. 摘要信息类 1.1 dominfo 获取配置等摘要信息 [root@hyperhost ~]# virsh dominfo --domain centos7.6 Id: 1 Name: cent ...