题目:

题目背景

SOURCE:NOIP2015-SHY-9

题目描述

小Y和小Z好不容易有机会相见啦,可是邪恶的小H却不想让他们相见。现在有一些城市,城市之间有双向路径相连,有路径相连的城市之间可以互相到达。小H可以任意选择一条路径,然后用他的邪恶力量污染这条路径,使得它不能被通行。虽然小Y和小Z在千辛万苦之后相遇了,但小Y非常害怕。她想让小Z告诉她,他们初始在哪些点对上,小H就可以选择一条路径污染使得他们不能相见。

注意:如果有一对点之间初始的时候就不联通,也是满足条件的,需要输出这对点。这是因为本来不联通,那么删一条边,当然也不联通。

输入格式

第一行两个数字 N 和 M 。N 表示城市数,M 表示路径数。
第二行到第 M+1 行,两个数 a 和 b。其中 1≤a,b≤N ,表示 a 和 b 之间有路径相连。

输出格式

输出一个整数,表示所求点对的数量

样例数据 1

输入  [复制]

2 1 
1 2

输出

1

备注

【样例说明】
点对(1,2)满足不能相见的条件。

【数据范围】
对 30% 的输入数据 :1≤N≤100,1≤M≤200
对 100% 的输入数据 :1≤N≤20000,1≤M≤40000

题解:

就是求每个边双连通分量···然后双连通分量内的点肯定是可以相互到达的,因此我们先算出所有的点对··再减去所有双连通分量中的点对数量(都是合法点对)即可···

另外注意处理重边以及断点的情况······md图论每次都被这两东西坑···

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=2e4+;
const int M=4e4+;
int first[N],next[M*],go[M*],tot=;
int n,m,dfn[N],low[N],cnt=;
int totgroup,size[N];
bool tag[M*],visit[N];
long long ans=;
inline int R()
{
char c;int f=;
for(c=getchar();c<''||c>'';c=getchar());
for(;c<=''&&c>='';c=getchar())
f=(f<<)+(f<<)+c-'';
return f;
}
inline void comb(int a,int b)
{
next[++tot]=first[a],first[a]=tot,go[tot]=b;
next[++tot]=first[b],first[b]=tot,go[tot]=a;
}
inline void tarjan(int u,int pre)
{
dfn[u]=low[u]=++cnt;
for(int e=first[u];e;e=next[e])
{
int v=go[e];
if(!dfn[v])
{
tarjan(v,e);low[u]=min(low[u],low[v]);
if(dfn[u]<low[v]) tag[e]=tag[e^]=true;
}
else
if((e^)!=pre) low[u]=min(low[u],dfn[v]);
}
}
inline void dfs(int u,int pre)
{
size[totgroup]++;visit[u]=true;
for(int e=first[u];e;e=next[e])
{
if(!tag[e]&&(e^)!=pre&&!visit[go[e]])
{
int v=go[e];dfs(v,e);
}
}
}
int main()
{
//freopen("a.in","r",stdin);
n=R(),m=R();int a,b;
for(int i=;i<=m;i++)
{
a=R(),b=R();
comb(a,b);
}
for(int i=;i<=n;i++)
if(!dfn[i]) tarjan(i,-);
for(int i=;i<=n;i++)
{
if(!visit[i]) totgroup++,dfs(i,-);
}
ans=(long long)n*(n-)/;
for(int i=;i<=totgroup;i++)
ans-=(long long)size[i]*(size[i]-)/;
cout<<ans<<endl;
return ;
}

刷题总结——date(ssoj)的更多相关文章

  1. csp刷题

    title: csp刷题 date: 2018-12-13 16:41:33 tags: --- Markdown 在第7个点挂了,,,不改了,,,太恶心了这种题QAQ,,,, 有谁想改的改完了告诉我 ...

  2. poj-2421-最小生成树刷题

    title: poj-2421-最小生成树刷题 date: 2018-11-20 20:30:29 tags: acm 刷题 categories: ACM-最小生成树 概述 做了几道最小生成树的题, ...

  3. hdu-3790最短路刷题

    title: hdu-3790最短路刷题 date: 2018-10-20 14:50:31 tags: acm 刷题 categories: ACM-最短路 概述 一道最短路的水题,,,尽量不看以前 ...

  4. hdu-1540线段树刷题

    title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...

  5. hdu-5023线段树刷题

    title: hdu-5023线段树刷题 date: 2018-10-18 13:32:13 tags: acm 刷题 categories: ACM-线段树 概述 这道题和上次做的那道染色问题一样, ...

  6. poj-2777线段树刷题

    title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...

  7. zoj-1610线段树刷题

    title: zoj-1610线段树刷题 date: 2018-10-16 16:49:47 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道简单的线段树区间染色问 ...

  8. mysql刷题(不定时更新)

    面试阶段大家基本都会问一些mysql的题,具体的高深理论以后再慢慢补充,但是刷题是不可避免的,下面直接上货 创建/删除表和索引系列 创建表 CREATE TABLE if not exists `te ...

  9. Buu刷题

    前言 希望自己能够更加的努力,希望通过多刷大赛题来提高自己的知识面.(ง •_•)ง easy_tornado 进入题目 看到render就感觉可能是模板注入的东西 hints.txt给出提示,可以看 ...

随机推荐

  1. kubernetes监控-prometheus(十六)

    监控方案 cAdvisor+Heapster+InfluxDB+Grafana Y 简单 容器监控 cAdvisor/exporter+Prometheus+Grafana Y 扩展性好 容器,应用, ...

  2. IntelliJ IDEA java设置程序运行时内存

    Run/Edit Configurations   Configuration/VM options  例如:设置运行内存为:-Xmx3m -Xms3m

  3. Java String Integer转换 练习:编程求字符串“100”和“150”按十进制数值做差后的结果以字符串形式输出。

    package com.swift; public class String_To_Integer_Test { public static void main(String[] args) { /* ...

  4. 如何挂载一个镜像文件(how to mount an image file)

    如何挂载一个镜像文件(how to mount an image file) 08/16/2012master 4 Comments 在使用KVM或Xen虚拟化的情况下,经常需要使用镜像文件(imag ...

  5. VueX源码分析(4)

    VueX源码分析(4) /module store.js /module/module.js import { forEachValue } from '../util' // Base data s ...

  6. mysql基本知识点

    1.建表格式:create table 表名(字段名 约束条件,字段名 约束条件,...);示例:create table brand(brand_id int unique primary key, ...

  7. MySQL中一条SQL的加锁分析

    MySQL中一条SQL的加锁分析 id主键 + RC id唯一索引 + RC id非唯一索引 + RC id无索引 + RC id主键 + RR id唯一索引 + RR id非唯一索引 + RR id ...

  8. COMP9021--6.17

    1. ''' '''the comment in the middle will be shown in your code while ranning 2. a=bc=a%bor we can si ...

  9. R-codes-tips

    1. 在shell执行R文件 chmod 0755 file.R Rscript file.R 2.  载入数据 data(dune) 3. attach() 将data.frame添加到R的搜索路径 ...

  10. ZOJ 2314 (sgu 194) Reactor Cooling (无源汇有上下界最大流)

    题意: 给定n个点和m条边, 每条边有流量上下限[b,c], 求是否存在一种流动方法使得每条边流量在范围内, 而且每个点的流入 = 流出 分析: 无源汇有上下界最大流模板, 记录每个点流的 in 和 ...