zoukankan      html  css  js  c++  java
  • 洛谷 P5782 [POI2001]和平委员会

    传送门

    #include <bits/stdc++.h>
    
    using namespace std;
    using ll = long long;
    using p = pair<int, int>;
    const int maxn(1e5 + 10);
    const int maxm(2e5 + 10);
    int ecnt, head[maxn];
    int tim, dfn[maxn], low[maxn];
    int scnt, id[maxn];
    bool vis[maxn];
    stack<int> st;
    
    struct edge {
        int to, nxt;
    } edges[maxm];
    
    template<typename T = int>
    inline const T read()
    {
        T x = 0, f = 1;
        char ch = getchar();
        while (ch < '0' || ch > '9') {
            if (ch == '-') f = -1;
            ch = getchar();
        }
        while (ch >= '0' && ch <= '9') {
            x = (x << 3) + (x << 1) + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
    
    template<typename T>
    inline void write(T x, bool ln)
    {
        if (x < 0) {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x / 10, false);
        putchar(x % 10 + '0');
        if (ln) putchar(10);
    }
    
    inline void addEdge(int u, int v)
    {
        edges[ecnt].to = v;
        edges[ecnt].nxt = head[u];
        head[u] = ecnt++;
    }
    
    inline int ls(int x)
    {
        return x * 2 - 1;
    }
    
    inline int rs(int x)
    {
        return x * 2;
    }
    
    inline int rev(int x)
    {
        return (x - 1 ^ 1) + 1;
    }
    
    void tarjan(int u)
    {
        dfn[u] = low[u] = ++tim;
        st.push(u);
        vis[u] = true;
        for (int i = head[u]; compl i; i = edges[i].nxt) {
            int v = edges[i].to;
            if (not dfn[v]) {
                tarjan(v);
                low[u] = min(low[u], low[v]);
            } else if (vis[v]) {
                low[u] = min(low[u], dfn[v]);
            }
        }
        if (dfn[u] == low[u]) {
            ++scnt;
            int v = -1;
            do {
                v = st.top();
                st.pop();
                vis[v] = false;
                id[v] = scnt;
            } while (u not_eq v);
        }
    }
    
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("input.txt", "r", stdin);
    #endif
        memset(head, -1, sizeof head);
        int n = read(), m = read();
        while (m--) {
            int u = read(), v = read();
            addEdge(u, rev(v));
            addEdge(v, rev(u));
        }
        for (int i = 1; i <= n * 2; ++i) {
            if (not dfn[i]) {
                tarjan(i);
            }
        }
        bool flag = false;
        for (int i = 1; i <= n; ++i) {
            if (id[ls(i)] == id[rs(i)]) {
                flag = true;
                break;
            }
        }
        if (flag) {
            puts("NIE");
        } else {
            for (int i = 1; i <= n; ++i) {
                if (id[ls(i)] < id[rs(i)]) {
                    write(ls(i), true);
                } else {
                    write(rs(i), true);
                }
            }
        }
        return 0;
    }
    
  • 相关阅读:
    ModSecurity for Nginx
    一些好用的nginx第三方模块
    ModSecurity--web应用防火墙
    mycat表拆分操作教程
    .NET解析HTML库集合
    MySQL分库分表
    Redis配置文件参数说明
    redis优化优秀文选
    MySQL订单分库分表多维度查询
    每秒处理10万订单乐视集团支付架构
  • 原文地址:https://www.cnblogs.com/singularity2u/p/13993148.html
Copyright © 2011-2022 走看看