zoukankan      html  css  js  c++  java
  • [洛谷P3469][POI2008]BLO-Blockade

    题目大意:给你一张无向图,求出删去每个点后有多少个有序点对无法互相到达

    题解:缩点,然后找割点$DP$,非割点的答案为$2n-2$(有序点对),割点的答案为它各个子联通块大小之积加上$2n-2$

    卡点:

    C++ Code:

    #include <cstdio>
    #define maxn 100010
    #define maxm 500010
    int head[maxn], cnt;
    struct Edge {
    	int to, nxt;
    } e[maxm << 1];
    inline void add(int a, int b) {
    	e[++cnt] = (Edge) {b, head[a]}; head[a] = cnt;
    }
    
    inline int min(int a, int b) {return a < b ? a : b;}
    int n, m;
    int DFN[maxn], low[maxn], idx;
    int sz[maxn];
    long long ans[maxn];
    void tarjan(int u, int fa = 0) {
    	DFN[u] = low[u] = ++idx;
    	int SZ = 0;
    	sz[u] = 1;
    	for (int i = head[u]; i; i = e[i].nxt) {
    		int v = e[i].to;
    		if (v != fa) {
    			if (!DFN[v]) {
    				tarjan(v, u);
    				low[u] = min(low[u], low[v]);
    				if (low[v] >= DFN[u])  {
    					ans[u] += static_cast<long long> (sz[v]) * SZ;
    					SZ += sz[v];
    				}
    				sz[u] += sz[v];
    			} else low[u] = min(low[u], DFN[v]);
    		}
    	}
    	ans[u] += static_cast<long long> (n - SZ - 1) * SZ;
    }
    
    int main() {
    	scanf("%d%d", &n, &m);
    	for (int i = 0, a, b; i < m; i++) {
    		scanf("%d%d", &a, &b);
    		add(a, b);
    		add(b, a);
    	}
    	tarjan(1);
    	for (int i = 1; i <= n; i++) {
    		printf("%lld
    ", ans[i] + n - 1 << 1);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Windows下Tomcat配置虚拟路径
    Windows下Tomcat配置虚拟主机
    Windows下Tomcat的下载安装与配置
    Windows系统下Jdk的下载安装与配置
    SpringBoot项目中Swagger的配置和使用
    Windows 10通过指定端口进行远程访问的防火墙设置
    Java反射
    Java导出Pdf格式表单
    排序
    二叉查找树
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/9908595.html
Copyright © 2011-2022 走看看