0
0

More than 3 years have passed since last update.

ABC177d memo

Last updated at Posted at 2020-09-27

本日より記録開始。
現状履修言語
C
C++
Ruby(基礎文法のみ)
python(基礎文法のみ)

入門 python3 購入

C++にて深さ優先探索(DFS)の実装(ABC177-D)

using namespace std;

int maxfriends=0;
int cnt=0;

vector seen;

void dfs(vector> &F,int v){
seen[v] = true;

for(auto next:F[v])
if(!seen[next]){
    dfs(F,next);
    cnt++;
}

}

int main(){
int N,M;
cin >> N >> M;

vector> fs(N) ;

for(int i=0; i<M; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    fs[a].push_back(b);
    fs[b].push_back(a);
}

seen.assign(N,false);
for(int i=0; i<N; i++){
    if(!seen[i]){
        cnt = 1;
        dfs(fs,i);
        maxfriends = max(maxfriends,cnt);
    }
}
cout << maxfriends << endl;

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0