Submission #497671

# Submission time Handle Problem Language Result Execution time Memory
497671 2021-12-23T14:03:51 Z hgmhc Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
51 ms 8404 KB
#include <bits/stdc++.h>
#define REP(i,a,b) for (auto i = (a); i <= (b); ++i)
#define SIZE(x) int(x.size())
#define debug(x) cerr << #x << " is " << x << endl
#define el '\n'
using namespace std; using ll = long long;

const int N = 1e5+3;
int n, m;
vector<int> adj[N];
vector<int> components;
bool visited[N];

void dfs(int s) {
    if (visited[s]) return;
    visited[s] = true;
    for (auto u : adj[s]) {
        dfs(u);
    }
}

void dfs1(int &x, int &l, int s = 1, int e = 0, int d = 0) {
    if (l < d) {
        x = s;
        l = d;
    }
    for (auto u : adj[s]) if (u != e) {
        dfs1(x,l,u,s,d+1);
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    REP(i,1,m) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    REP(i,1,n) {
        if (not visited[i]) {
            components.push_back(i);
            dfs(i);
        }
    }
    int answer = 0;
    for (auto s : components) {
        int x = s, l = 0;
        dfs1(x,l,s);
        dfs1(x,l = 0,x);
        answer += l+1;
    }
    cout << answer;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3108 KB Output is correct
2 Correct 18 ms 3780 KB Output is correct
3 Correct 22 ms 4320 KB Output is correct
4 Correct 35 ms 4868 KB Output is correct
5 Correct 35 ms 5324 KB Output is correct
6 Correct 41 ms 5912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 8404 KB Output is correct
2 Correct 4 ms 3148 KB Output is correct
3 Correct 7 ms 3660 KB Output is correct
4 Correct 10 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 5 ms 3148 KB Output is correct
6 Correct 7 ms 3688 KB Output is correct
7 Correct 10 ms 4272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3108 KB Output is correct
2 Correct 18 ms 3780 KB Output is correct
3 Correct 22 ms 4320 KB Output is correct
4 Correct 35 ms 4868 KB Output is correct
5 Correct 35 ms 5324 KB Output is correct
6 Correct 41 ms 5912 KB Output is correct
7 Correct 27 ms 8404 KB Output is correct
8 Correct 4 ms 3148 KB Output is correct
9 Correct 7 ms 3660 KB Output is correct
10 Correct 10 ms 4044 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 5 ms 3148 KB Output is correct
16 Correct 7 ms 3688 KB Output is correct
17 Correct 10 ms 4272 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 1 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 1 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 3 ms 2636 KB Output is correct
29 Correct 51 ms 5984 KB Output is correct
30 Correct 11 ms 4296 KB Output is correct
31 Correct 26 ms 6216 KB Output is correct
32 Correct 23 ms 4824 KB Output is correct
33 Correct 45 ms 5960 KB Output is correct
34 Correct 32 ms 5144 KB Output is correct
35 Correct 34 ms 6056 KB Output is correct
36 Correct 33 ms 5452 KB Output is correct
37 Correct 32 ms 5964 KB Output is correct
38 Correct 48 ms 5644 KB Output is correct
39 Correct 31 ms 6068 KB Output is correct