UOJ UR#9 App管理器

來源:互聯網
上載者:User

標籤:pre   target   char   題目   read   const   color   去掉   ble   

題目傳送門

題目大意大概就是給你一個混合圖(既有有向邊又有無向邊),對於每條無向邊,u-v,問刪去u->v,或刪去v->u那條可以使新圖強連通。(保證資料有解)。

這道題前幾個資料點送分。

枚舉每一條邊,先將它去掉,遍曆圖,如果可以達到所有點,即強連通。

比如去掉u->v,其實只要dfs(u),判斷是否能到達v即可。
可以直接刪去,否則刪另一條邊,刪去後因為圖強連通,所以對之後的操作無影響。

code:

#include <cstdio>#include <cstring>using namespace std;int read(){    char c;while(c=getchar(),c<‘0‘||c>‘9‘);    int x=c-‘0‘;while(c=getchar(),c>=‘0‘&&c<=‘9‘)x=x*10+c-‘0‘;    return x;}const int MAXN=5005;int N,M,ide[MAXN<<1],vis[MAXN];int head[MAXN],to[MAXN<<1],nxt[MAXN<<1],cnt;struct node{    int x,y,o,d;}edge[MAXN];void add(int x,int y){    to[cnt]=y;    nxt[cnt]=head[x];    head[x]=cnt;    cnt++;}void dfs(int now){    vis[now]=1;        for(int i=head[now];i!=-1;i=nxt[i]){            if(!ide[i]&&!vis[to[i]]){                dfs(to[i]);            }        }}int main(){    N=read(),M=read();    memset(head,-1,sizeof head);        for(int i=1;i<=M;i++){            int x=read(),y=read(),o=read();            add(x,y);if(!o)add(y,x);            edge[i]=(node){x,y,o,cnt-1};        }        for(int i=1;i<=M;i++){            if(edge[i].o){puts("0");continue;}            memset(vis,0,sizeof vis);            ide[edge[i].d]=1;            dfs(edge[i].y);            if(vis[edge[i].x]){                puts("0");continue;            }            else{                ide[edge[i].d]=0;                ide[edge[i].d-1]=1;            }            puts("1");continue;        }    return 0;}

 

UOJ UR#9 App管理器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.