zoukankan      html  css  js  c++  java
  • 题解 [JSOI2015]最小表示

    link

    Solution

    md,智障了。

    首先看出一个结论,就是说一条边 ((u,v)) 可以删当且仅当在原图中删掉改变该边 (u) 仍能到达 (v)

    因为这是一个 DAG,所以我们可以拓排之后从后往前扫,然后用 bitset 维护连通性。

    Code

    #include <bits/stdc++.h>
    using namespace std;
     
    #define Int register int
    #define MAXM 100005
    #define MAXN 30005
     
    template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
    template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
    template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
    template <typename T> inline void chkmax (T &a,T b){a = max (a,b);}
    template <typename T> inline void chkmin (T &a,T b){a = min (a,b);}
    
    vector <int> g[MAXN],h[MAXN],sta[MAXN];
    int n,m,px[MAXM],py[MAXM],dep[MAXN],deg[MAXN];
    
    void topo (){
    	queue <int> q;
    	for (Int i = 1;i <= n;++ i){
    		deg[i] = h[i].size();
    		if (!deg[i]) dep[i] = 1,q.push (i);
    	}
    	while (!q.empty()){
    		int u = q.front();
    		q.pop (),sta[dep[u]].push_back (u);
    		for (Int v : g[u]) if (!-- deg[v]) dep[v] = dep[u] + 1,q.push (v);
    	}
    }
    
    bitset <MAXN> S[MAXN];
    
    signed main(){
    	read (n,m);
    	for (Int i = 1;i <= m;++ i) read (px[i],py[i]),g[px[i]].push_back (py[i]),h[py[i]].push_back (px[i]);
    	topo ();int ans = 0;
    	for (Int i = n;i >= 1;-- i)
    		for (Int u : sta[i]){
    			sort (g[u].begin(),g[u].end(),[](int x,int y){return dep[x] < dep[y];});
    			S[u][u] = 1;
    			for (Int v : g[u])
    				if (S[u][v]) ans ++;
    				else S[u] |= S[v];
    		}
    	write (ans),putchar ('
    ');
    	return 0;
    }
    
  • 相关阅读:
    2020面试有感(1)
    多线程与异步
    GP-荧光免疫分析仪SDK 协议
    FastReport模板设计和调用
    EF的多线程与分库架构设计实现(2)
    HTML页面转化为带有水印的PDF文件
    利用 html2canvas+jsPDF 把 HTML元素 转化为PDF文件,以及遇到的坑
    前端json数据格式化显示
    单元测试——引入Vuex
    单元测试——引入vue-router和APP.vue文件
  • 原文地址:https://www.cnblogs.com/Dark-Romance/p/15434768.html
Copyright © 2011-2022 走看看