zoukankan      html  css  js  c++  java
  • 【UR #9】App 管理器

    UOJ小清新题表

    题目内容

    UOJ链接

    一句话题意:给出一个强联通的混合图,有一些有向边和无向边。删除一些边使其维持强联通的状态,求删边方案。

    数据范围

    (1leq nleq 5000,0leq mleq 5000)

    思路

    大水题,枚举边是否删除,每次直接dfs一遍看删除后边的两个端点是否联通。要是不能联通,则删除反向边即可。

    复杂度 (O(nm)) ,稳过。

    UPD:官方题解给出了证明,一定是正确的。不过谁做题的时候想证明呢

    代码

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=5e3+10;
    int n,m;
    bool notexist[maxn<<1];
    
    struct Edge{
        int from,to,nxt;
    }e[maxn<<1];
    
    struct Node{
        int from,to,t,id;
    }E[maxn<<1];
    
    inline int read(){
        int x=0,fopt=1;char ch=getchar();
        for(;!isdigit(ch);ch=getchar())if(ch=='-')fopt=-1;
        for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+ch-48;
        return x*fopt;
    }
    
    int head[maxn],cnt;
    inline void add(int u,int v){
        e[++cnt].from=u;
        e[cnt].to=v;
        e[cnt].nxt=head[u];
        head[u]=cnt;
    }
    
    bool vis[maxn];
    void dfs(int u,int t){
        vis[u]=1;
        if(vis[t])return;
        for(int i=head[u];i;i=e[i].nxt){
            int v=e[i].to;
            if(!notexist[i]&&!vis[v])dfs(v,t);
        }
    }
    
    int main(){
        n=read();m=read();
        for(int i=1;i<=m;i++){
            int u=read(),v=read(),t=read();
            if(t==0){
                add(u,v);
                add(v,u);
            }else add(u,v);
            E[i]=(Node){u,v,t,cnt};
        }
        for(int i=1;i<=m;i++){
            if(E[i].t){
                puts("0");
                continue;
            }
            memset(vis,0,sizeof(vis));
            notexist[E[i].id]=1;
            dfs(E[i].to,E[i].from);
            if(vis[E[i].from]){
                puts("0");
            }else{
                notexist[E[i].id]=0;
                notexist[E[i].id-1]=1;
                puts("1");
            }
        }
        return 0;
    }
    
  • 相关阅读:
    .net下的span和memory
    linux下mysql自动备份脚本
    mysqldump参数详细说明(转)
    Apache参数的优化(转)
    shell中set的用法(转)
    [转贴] start-stop-daemon命令
    Linux命令service
    分享三个好用的装饰器(转)
    python语法32[装饰器decorator](转)
    mongodb exception in initAndListen: 12596 old lock file, terminating解决方法
  • 原文地址:https://www.cnblogs.com/Midoria7/p/13531856.html
Copyright © 2011-2022 走看看