1 条题解

  • 0
    @ 2025-10-8 16:54:04
    #include<bits/stdc++.h>
    using namespace std;
    const int N=3e4+10;
    vector<int>G[N];
    bool vis[N];
    int ans;
    void dfs(int x){
    	ans++;
    	vis[x]=true;
    	for(int y:G[x])
            if(!vis[y])
                dfs(y);
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
    	int n,m,k;cin>>n>>m>>k;
    	for(int i=1,x,y;i<=m;i++){
    		cin>>x>>y;
    		G[x].push_back(y);
    		G[y].push_back(x);
    	}
        memset(vis,false,sizeof(vis));
    	for(int i=1,x;i<=k;i++){
            cin>>x;
    		for(int y:G[x])
    			vis[y]=true;
    	}
    	ans=0;dfs(1);
    	cout<<n-ans<<'\n';
        return 0;
    }
    
    • 1

    【递归:Floodfill】统计无法到点1的点数[USACO09JAN] Earthquake Damage G

    信息

    ID
    796
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    25
    已通过
    9
    上传者