【dfs找不在简单路径的点】ZOJ 10th Anniversary Contest C ZOJ 3583

纯YY

int g[111][111];
bool vis[111];
bool visit[111];
int pre[111];
int n,m,s,t;
void dfs(int u){
    int i;
    if(u==t || vis[u]){
        while(u!=s){
            vis[u] = 1;
            u = pre[u];
        }
        return ;
    }
    for(i=0;i<n;i++){
        if(g[u][i] && !visit[i]){
            pre[i] = u;
            visit[i] = 1;
            dfs(i);
            visit[i] = 0;
        }
    }
}
int main(){
    while(scanf("%d%d%d%d",&n,&m,&s,&t) !=-1){
        int i,j;
        memset(g,0,sizeof(g));
        while(m--){
            int x,y;
            scanf("%d%d",&x,&y);
            g[x][y] = g[y][x] = 1;
        }
        for(i=0;i<n;i++){
            vis[i] = 0;
            pre[i] = -1;
            visit[i] = 0;
        }
        visit[s] = 1;
        dfs(s);
        vis[s] = vis[t] = 1;
        int ans = 0;
        for(i=0;i<n;i++){
            if(!vis[i])ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}



















你可能感兴趣的:(c,ini)