#include <string>
#include <iostream>
#include <vector>

using namespace std;

//1차 연결 탐색
vector<vector <int>> net_1(int n, vector<vector<int>> computers){
    vector <vector<int>> res;  // 1차 연결 탐색
    for (int i = 0; i<n; i++){
        for (int j = 0; j<n; j++){
            if (computers.at(i).at(j) == 1 ){
                res.at(i).push_back(j);
            }
        }        
    }    
}

int solution(int n, vector<vector<int>> computers) {
    
    int answer = 0;
    vector<vector <int>> net1 = net_1(n, computers); //1차 탐색 결과
    vector<int> net; //1행만 저장할 변수
    int target;  //검색할 타겟 변수
    int m;  //행의 길이 저장 변수
    
    for(int i = 0; i<n-1; i++){
        net = net1.at(i);
        m = net1.at(i+1).size();
        //i번째줄과 i+1번째 줄에 공통 요소가 있으면 합병
        for(int j = 0; j<m; j++){
            target = net1.at(i+1).at(j);
            auto it = find(net.begin(), net.end(), target);
            if(it != net.end()) { 
                // v1의 끝에 v2를 추가
                net1.at(i).insert(net1.at(i).end(), net1.at(i+1).begin(), net1.at(i+1).end());
                //겹치는 요소 삭제
                sort(net1.at(i).begin(), net1.at(i).end());
                net1.at(i).erase(unique(net1.at(i).begin(),net1.at(i).end()), net1.at(i).end());
                net1.at(i+1).erase;
                i--;
                n--;
             }
        }
    }
    
    
    
    
    
    return answer;
}
#include <string>
#include <vector>

using namespace std;

//한줄 읽기
vector<int> search_net(vector<int> computer, int com_num) {
    int len computer.size();
    vector<int> res;
    
    for (int i = 0; i<len; i++){
        if (computer.at(i) == 1) {
            //연결된 컴퓨터 인덱스 저장
            res.push_back(i);
        }
    }
}

//두줄 읽기
vector<int> serch_all_net(vector<vector<int>> computers, vector<int> network_ing){
    int len = network_ing.size();
    vector<int> res;
    vector<int> save;
    
    for (int i = 0; i<len; i++){
        save = search_net(computers[network_ing.at(i)]);
        
        // res의 끝에 save를 추가
        res.insert(res.end(), save.begin(), save.end());
        
        //겹치는 요소 삭제
        sort(res.begin(), res.end());
        res.erase(unique(res.begin(),res.end()), res.end());
    }    
}

int solution(int n, vector<vector<int>> computers) {
    //첫 요소를 for문으로 긁고 1인 값의 인덱스들을 저장
    //1인 인덱스번째 요소의 1인값의 인덱스를 저장
    //중복은 저장하지 않도록함
    //저장되지 않을때까지 반복
    //저장된 모든 인덱스를 연결된 네트워크에 추가
    //이후 연결된 네트워크에 저장된 인덱스를 제외한 인덱스를 탐색하여 다음 네트워크 구성 탐색
    int answer = 0;
    vector<int> network_1; //연결된 네트워크
    vector<int> network_ing; //연결 찾고있는 네트워크
    
    while(people.begin() != people.end()); {
        for(int i = 0; i<n; i++){
            network_ing = search_net(computers[i], i);
        }
    }
    return answer;
}