UVA11080 - Place the Guards (二分图染色)

题意: 给出一个无向图,  有联通地方,  求联通个数。 (好吧, 我还不是很懂)

 

二分图染色:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int MAXNODE = 510;
const int MAXEDGE = 100010;

struct Edge
{
    int v, next;
    Edge() {}
    Edge(int v, int next): v(v), next(next){} 
} E[MAXEDGE];

int head[MAXNODE], color[MAXNODE];
int tot, n, m;
int s, b;
int sum;
 
void addEdge(int u, int v)
{
    E[tot]=Edge(v, head[u]);
    head[u]=tot++;
}

bool bipartite(int u)
{
    if(color[u]==1) s++;
    else b++;
    
    for(int i=head[u]; i!=-1; i=E[i].next)
    {
        int v=E[i].v;
        if(color[v] == color[u]) return false;
        if(!color[v])
        {
            color[v]=3-color[u];
            if(!bipartite(v)) return false;
        }
    }
    return true;
}

void init()
{
    scanf("%d%d", &n, &m);
    memset(head, -1, sizeof(head));
    //memset(color, 0, sizeof(color));
    tot=0; sum=0;
    
    int u, v;
    for(int i=0; i<m; i++)
    {
        scanf("%d%d", &u, &v);
        addEdge(u, v);
        addEdge(v, u); 
    }
}

int solve()
{
    //所有颜色未定, 将1这个节点定义成颜色1, 然后dfs进行染色 ;
    memset(color, 0, sizeof(color));
    //color[1]=1;
    for(int i=0; i<n; i++)
    {
        if(color[i]==0)
        {
            s=b=0;
            color[i]=1;
            if(!bipartite(i)) return -1;
            sum += max(1, min(s, b));
        }
    }
    return sum;
}
int main()
{
    //scanf("%d%d", &n, &m);
    int T;
    scanf("%d", &T);
    while(T--)
    {
        init();
        printf("%d\n", solve());
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/soTired/p/5323315.html

a navigation guard. This error message is related to the use of navigation guards in the Vue.js router. Navigation guards are functions that are used to intercept and control navigation to different routes in your application. They can be used to prevent unauthorized access to certain pages, redirect users to specific pages, or perform other actions before the navigation is completed. The "next" callback is a function that must be called inside a navigation guard to allow the navigation to proceed. If the "next" callback is not called, the navigation will not be completed, and the user will be stuck on the current page. The error message "The 'next' callback was never called inside of a navigation guard" indicates that the "next" callback function was not called inside one of your navigation guards. To resolve this error, make sure that you call the "next" callback function inside each of your navigation guards. Here is an example of a navigation guard that uses the "next" callback: ``` router.beforeEach((to, from, next) => { // Check if the user is authenticated if (isAuthenticated()) { // Allow the navigation to proceed next() } else { // Redirect the user to the login page next('/login') } }) ``` In this example, the "next" callback function is called either to allow the navigation to proceed or to redirect the user to the login page if they are not authenticated. Make sure to include the "next" callback function in your navigation guards to avoid the "next" callback was never called error.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值