Submission #522232

# Submission time Handle Problem Language Result Execution time Memory
522232 2022-02-04T08:45:55 Z blue Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
78 ms 12916 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;

using vi = vector<int>;
using ll = long long;

#define sz(x) int(x.size())

const int mx = 100'000;

vi edge[1+mx];
int n, m;

int res = 0;

vi visit(1+mx, 0);

vector< pair<int, int> > V; //dist, node

void dfs(int u, int d)
{
    // cerr << "dfs " << u << ' ' << d << '\n';
    V.push_back({-d, u});
    visit[u] = 1;
    for(int v: edge[u])
    {
        if(visit[v]) continue;
        dfs(v, d+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;

    for(int j = 1; j <= m; j++)
    {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    for(int i = 1; i <= n; i++)
    {
        if(visit[i]) continue;
            // cerr << "component = " << i << '\n';
        dfs(i, 0);
        sort(V.begin(), V.end());
        for(auto y: V) visit[y.second] = 0;

        int src = V[0].second;
        V.clear();

        // cerr << "cleared\n";

        dfs(src, 0);
        sort(V.begin(), V.end());

        res -= V[0].first - 1;

        V.clear();
    }

    cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4064 KB Output is correct
2 Correct 18 ms 5068 KB Output is correct
3 Correct 27 ms 5876 KB Output is correct
4 Correct 39 ms 7200 KB Output is correct
5 Correct 49 ms 7752 KB Output is correct
6 Correct 78 ms 8512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12916 KB Output is correct
2 Correct 4 ms 3532 KB Output is correct
3 Correct 9 ms 3916 KB Output is correct
4 Correct 12 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3020 KB Output is correct
3 Correct 2 ms 3020 KB Output is correct
4 Correct 2 ms 3020 KB Output is correct
5 Correct 6 ms 3848 KB Output is correct
6 Correct 11 ms 4548 KB Output is correct
7 Correct 16 ms 5448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3020 KB Output is correct
3 Correct 3 ms 3024 KB Output is correct
4 Correct 2 ms 3020 KB Output is correct
5 Correct 2 ms 3020 KB Output is correct
6 Correct 2 ms 3020 KB Output is correct
7 Correct 2 ms 3064 KB Output is correct
8 Correct 2 ms 3020 KB Output is correct
9 Correct 2 ms 3020 KB Output is correct
10 Correct 2 ms 3020 KB Output is correct
11 Correct 2 ms 3068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4064 KB Output is correct
2 Correct 18 ms 5068 KB Output is correct
3 Correct 27 ms 5876 KB Output is correct
4 Correct 39 ms 7200 KB Output is correct
5 Correct 49 ms 7752 KB Output is correct
6 Correct 78 ms 8512 KB Output is correct
7 Correct 40 ms 12916 KB Output is correct
8 Correct 4 ms 3532 KB Output is correct
9 Correct 9 ms 3916 KB Output is correct
10 Correct 12 ms 4472 KB Output is correct
11 Correct 2 ms 3020 KB Output is correct
12 Correct 2 ms 3020 KB Output is correct
13 Correct 2 ms 3020 KB Output is correct
14 Correct 2 ms 3020 KB Output is correct
15 Correct 6 ms 3848 KB Output is correct
16 Correct 11 ms 4548 KB Output is correct
17 Correct 16 ms 5448 KB Output is correct
18 Correct 2 ms 3020 KB Output is correct
19 Correct 2 ms 3020 KB Output is correct
20 Correct 3 ms 3024 KB Output is correct
21 Correct 2 ms 3020 KB Output is correct
22 Correct 2 ms 3020 KB Output is correct
23 Correct 2 ms 3020 KB Output is correct
24 Correct 2 ms 3064 KB Output is correct
25 Correct 2 ms 3020 KB Output is correct
26 Correct 2 ms 3020 KB Output is correct
27 Correct 2 ms 3020 KB Output is correct
28 Correct 2 ms 3068 KB Output is correct
29 Correct 76 ms 8508 KB Output is correct
30 Correct 10 ms 4044 KB Output is correct
31 Correct 26 ms 6920 KB Output is correct
32 Correct 16 ms 4940 KB Output is correct
33 Correct 32 ms 7204 KB Output is correct
34 Correct 26 ms 5600 KB Output is correct
35 Correct 28 ms 6980 KB Output is correct
36 Correct 38 ms 6748 KB Output is correct
37 Correct 34 ms 7164 KB Output is correct
38 Correct 50 ms 7820 KB Output is correct
39 Correct 29 ms 6988 KB Output is correct