답안 #680304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680304 2023-01-10T14:33:40 Z KG07 Cijanobakterije (COCI21_cijanobakterije) C++14
0 / 70
63 ms 9048 KB
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
vector<int> h[100000];
int a[100000];
bool b[100000];
int c[100000];
pair<int, int> d[100000];
int find(int x){
    if(x == a[x])return x;
    else return a[x] = find(a[x]);
}
queue<pair<int, int>> q;

int main() {
    // Write C++ code here
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)a[i] = i;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        h[u].push_back(v);
        h[v].push_back(u);
        a[find(u)] = find(v);
        b[find(u)] = true;
    }
    for(int i = 1; i <= n; i++){
        if(!b[i]){
            d[i] = {i, i};
            for(int j = 0; j < h[i].size(); j++)q.push({h[i][j], i});
        }
        while(!q.empty()){
            int u = q.front().first;
            int v = q.front().second;
            q.pop();
            c[u] = c[v] + 1;
            if(c[u] > c[d[find(u)].first]){d[find(u)].second = d[find(u)].first; d[find(u)].first = u;}
            else if(c[u] > c[d[find(u)].second])d[find(u)].second = u;
            for(int j = 0; j < h[u].size(); j++)if(h[u][j] != v)q.push({h[u][j], u});
        }
    }
    int s = 0;
    for(int i = 1; i <= n; i++){
        //cout << i << " " << a[i] << " " << b[i] << " " << c[i] << " " << c[d[i].first] + c[d[i].second] << "\n";
        if(!b[i])s += c[d[i].first] + c[d[i].second];
    }
    cout << s;

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:31:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             for(int j = 0; j < h[i].size(); j++)q.push({h[i][j], i});
      |                            ~~^~~~~~~~~~~~~
Main.cpp:40:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for(int j = 0; j < h[u].size(); j++)if(h[u][j] != v)q.push({h[u][j], u});
      |                            ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 9048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3540 KB Output isn't correct
2 Halted 0 ms 0 KB -