Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求改错 wa着呢

Posted by x279914095 at 2011-11-04 14:14:06 on Problem 2942
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
vector <int> block[1001];
int n,m;
int tot=1,index=1,color[1011];
bool Stack[1011],attend[1011];
bool map[1011][1011];
int dfn[1011],low[1011];
int S1[1011],S2[1011],top1,top2;
int min(const int &a,const int &b)
{
    return a>b?b:a;
}
void push(int *stack,int &top,int data)
{
    stack[++top]=data;
}
void tarjan(int id,int fa)
{
    dfn[id]=low[id]=index++;
    push(S1,top1,id);
    Stack[id]=1;
    for(int i=1;i<=n;i++)
    {
        if(map[id][i]==0)  continue;

        if(!dfn[i])
        {
            tarjan(i,id);
            if(low[i]>=dfn[id])
            {
                while(1)
                {
                    int tmp=S1[top1];
                    top1--;
                    Stack[tmp]=0;
                    block[tot].push_back(tmp);
                    if(tmp==i)
                        break;
                }
                block[tot++].push_back(id);
            }
            low[id]=min(low[id],low[i]);
        }
        else if(i!=fa)
        {
            low[id]=min(low[id],dfn[i]);
        }
    }
}
bool dfs(int *p,int start,int Color,int fa)
{
    if(color[start]!=Color)
       return true;
    color[start]=Color;
    for(int i=1;i<=n;i++)
    {
        if(map[i][start] && p[i] && i!=fa)
           return dfs(p,i,3-Color,start);
    }
    return false;
}
void paint(int i)
{
    int p[1001],start,size=block[i].size();
    memset(p,0,sizeof(p));
    if(size<3)
      return ;
    while(!block[i].empty())
    {
        p[block[i].back()]=1;
        start=block[i].back();
        block[i].pop_back();
    }
    if(dfs(p,start,1,-1) && size>=3)
    {
        for(int i=1;i<=1000;i++)
           attend[i]=(p[i]|attend[i]);
    }
}
int main()
{
    while(1)
    {
        top1=top2=-1; index=tot=1;
        memset(low,0,sizeof(low));
        memset(dfn,0,sizeof(dfn));
        memset(Stack,0,sizeof(Stack));
        memset(attend,0,sizeof(attend));
        memset(map,1,sizeof(map));
        scanf("%d %d",&n,&m);
        for(int i=0;i<=n;i++)
            map[i][i]=0;
        if(n==0 && m==0)
            break;
        for(int i=0;i<m;i++)
        {
            int x,y;
            scanf("%d %d",&x,&y);
            map[x][y]=map[y][x]=0;
        }
        for(int i=1;i<=n;i++)
            if(!dfn[i])
                tarjan(i,1);
        int res=0;
        for(int i=1;i<tot;i++)
        {
            paint(i);
            block[i].clear();
        }
        for(int i=1;i<=n;i++)
             if(!attend[i]) res++;
        printf("%d\n",res);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator