zoukankan      html  css  js  c++  java
  • HDU 5413 CRB and Roads bitset (看题解)

    HDU 5413

    居然不知道acyclic是没有环的意思GG。

    如果是拓扑图的话, 用bitset暴力更新就完事了。

    #include<bits/stdc++.h>
    #define LL long long
    #define LD long double
    #define ull unsigned long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ALL(x) (x).begin(), (x).end()
    #define fio ios::sync_with_stdio(false); cin.tie(0);
    
    using namespace std;
    
    const int N = 2e4 + 2;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1e-8;
    const double PI = acos(-1);
    
    template<class T, class S> inline void add(T &a, S b) {a += b; if(a >= mod) a -= mod;}
    template<class T, class S> inline void sub(T &a, S b) {a -= b; if(a < 0) a += mod;}
    template<class T, class S> inline bool chkmax(T &a, S b) {return a < b ? a = b, true : false;}
    template<class T, class S> inline bool chkmin(T &a, S b) {return a > b ? a = b, true : false;}
    
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int n, m, ans, deg[N];
    vector<int> G[N];
    bitset<20000> bit[20000];
    bool vis[N];
    
    void dfs(int u) {
        if(vis[u]) return;
        vis[u] = true;
        for(auto &v : G[u]) {
            dfs(v);
            bit[u] |= bit[v];
        }
        for(auto &v : G[u]) {
            if(bit[u][v]) {
                ans++;
            }
            else {
                bit[u][v] = 1;
            }
        }
    }
    
    int main() {
    
        int T; scanf("%d", &T);
        while(T--) {
            scanf("%d%d", &n, &m);
            for(int i = 0; i < n; i++) {
                G[i].clear();
                bit[i].reset();
                deg[i] = 0;
                vis[i] = 0;
            }
            for(int i = 1; i <= m; i++) {
                int u, v;
                scanf("%d%d", &u, &v);
                u--; v--;
                G[u].push_back(v);
                deg[v]++;
            }
    
            ans = 0;
    
            for(int i = 0; i < n; i++) {
                if(!deg[i]) {
                    dfs(i);
                }
            }
    
            printf("%d
    ", ans);
        }
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    poj 3126 Prime Path
    poj 2255 Tree Recovery
    spoj 7259 LITE
    poj 1742 Coins
    poj 1915 Knight Moves
    poj 2352 Stars
    【祝贺】gooogleman嵌入式开发板联盟图标设计完成,Let me Show!
    【讨论】TE6410/OK6410 开发板dnw c0008000是什么意思, ?
    【讨论】为什么我的300W摄像头偶尔会拍照不成功?
    【探讨】关于2440 触摸屏驱动的怪异现象分析
  • 原文地址:https://www.cnblogs.com/CJLHY/p/11160368.html
Copyright © 2011-2022 走看看