PersonalCorpus 版 (精华区)

40261 2002-10-09 22:23:35 Accepted
1311 C++ 00:00.03 396K  Big Guava


bool dl[100][100],c[100];
int dfn[100],low[100],rootx,tempi, n;

void func4sub(int v)
{
    int u;
    for (u=0;u<n;u++) if (dl[v][u]) if (dfn[u]==0) {
        tempi++;
        dfn[u]=tempi;
        low[u]=tempi;
        func4sub(u);
        if (low[v]>low[u]) low[v]=low[u];
        if (low[u]>=dfn[v])
            if (v!=0) c[v]=true; else rootx++;
    } else if (low[v]>dfn[u]) low[v]=dfn[u];
}
void func4()
{
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    memset(c,0,sizeof(c));
    tempi=1; dfn[0]=tempi; low[0]=tempi;  rootx=0;
    func4sub(0);
    if (rootx>1) c[0]=true;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\0acm\\zju\\i1311","r",stdin);
    freopen("c:\\0acm\\zju\\o1311","w",stdout);
#endif

    int i,j,k;
    char s[1000];
    while (1) {
        scanf("%d\n",&n);
        if (n==0) break;
        memset(dl,0,sizeof(dl));
        while (1) {
            gets(s);
            i=0;
            while (!isdigit(s[i])) i++;
            sscanf(s+i,"%d",&j); j--;
            if (j==-1) break;
            while (isdigit(s[i])) i++;
            while (1) {
                while ((!isdigit(s[i]))&&(s[i]!=0)) i++;
                if (s[i]==0) break;
                sscanf(s+i,"%d",&k); k--;
                dl[j][k]=true; dl[k][j]=true;
                while (isdigit(s[i])) i++;
            }
        }
        func4();
        k=0; for (i=0;i<n;i++) if (c[i]) k++;
        printf("%d\n",k);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.873毫秒