Gym 101490C Brexit(搜索)

https://vjudge.net/contest/186932#problem/C 
给定一个图。表示一个王国,给你s,代表你的家乡。 
t,代表最开始分裂的城市,如果一个城市,和他邻接的一半城市都分裂了,那么他也要分裂。问你能否使你的家乡分裂。 
我感觉,dfs我是不太擅长的qwq。直接广搜也是阔以的。 
存一下度数,然后邻接的都减一下度数。就酱紫
代码:


//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
//https://www.cnblogs.com/zzrturist/    //博客园
//https://blog.csdn.net/qq_44134712     //csdn

using namespace std;

typedef long long ll;
const ll N=2e5+10;
const int mod=1000000007;

vector<int>n[N];
int disv[N];
int a,b,c,d;

void dfs(int t){
   for(int i=0;i<n[t].size();i++){
       int h=n[t][i];
       disv[h]--;
       if(disv[h]<=0){
           continue;
       }
       if(disv[h]>n[h].size()/2){
           continue;
       }
       else{
           disv[h]=0;
           dfs(h);
       }
   }
}

int main()
{
    int x,y;
    cin >> a >> b >> c >> d;
    memset(disv,0,sizeof(disv));
    for(int i=1;i<=b;i++){
        cin >> x >> y;
        n[x].push_back(y);
        n[y].push_back(x);
        disv[x]++;
        disv[y]++;
    }
    if(c==d){
        cout << "leave";
        return 0;
    }
    disv[d]=0;
    dfs(d);
    if(disv[c]>0){
        cout << "stay";
    }
    else{
        cout << "leave";
    }
    return 0;
}

 


//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
//https://www.cnblogs.com/zzrturist/    //博客园
//https://blog.csdn.net/qq_44134712     //csdn

using namespace std;

typedef long long ll;
const ll N=2e5+10;
const int mod=1000000007;

vector<int>n[N];
int flag[N];
int disv[N];
int vis[N];
int a,b,c,d;

void bfs(int t){
    queue<int>q;
    q.push(t);
    flag[t]=1;
    while(!q.empty()){
        int g=q.front();
        q.pop();
        if(g==c){
            cout << "leave";
            return ;
        }
        for(int i=0;i<n[g].size();i++){
            int h=n[g][i];
            vis[h]++;
            if(vis[h]*2>=disv[h]&&flag[h]==0){
                q.push(h);
                flag[h]=1;
            }
        }
    }
    cout << "stay";
    return ;
}

int main()
{
    int x,y;
    cin >> a >> b >> c >> d;
    memset(flag,0,sizeof(flag));
    memset(disv,0,sizeof(disv));
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=b;i++){
        cin >> x >> y;
        n[x].push_back(y);
        n[y].push_back(x);
        disv[x]++;
        disv[y]++;
    }
    bfs(d);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值