답안 #508483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508483 2022-01-13T11:23:22 Z Hacv16 Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
80 ms 60920 KB
#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define endl '\n'
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define bn binary_search
#define lb lower_bound
#define up upper_bound
#define np next_permutation
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define mdc(x, y) __gcd(x, y)
#define dbg(x) cout << #x << ": " << "[ " << x << " ]\n"

typedef int ii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX = 2e6 + 15;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int VAR[4] = {-1, 1, 0, 0};

ll n, m, v1, v2, ans, mx, id;
vector<int> adj[MAX], seen(MAX, false);

void setIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
}

void dfs(int x, int p, int d){
    seen[x] = true;
    if(d > mx) id = x, mx = d;

    for(auto v : adj[x]){
        if(v == p) continue;
        dfs(v, x, d + 1);
    }
}

int diam(int r){
    mx = -INF;
    dfs(r, -1, 1);

    mx = -INF;
    dfs(id, -1, 1);

    return mx;
}

int main(){
    setIO();

    cin >> n >> m;

    while(m--){
        int u, v;
        cin >> u >> v;

        adj[u].pb(v);
        adj[v].pb(u);
    }

    for(int i = 1; i <= n; i++){
        if(!seen[i]) ans += diam(i);
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 55628 KB Output is correct
2 Correct 39 ms 56140 KB Output is correct
3 Correct 59 ms 56724 KB Output is correct
4 Correct 57 ms 57260 KB Output is correct
5 Correct 65 ms 57756 KB Output is correct
6 Correct 71 ms 58336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 60920 KB Output is correct
2 Correct 33 ms 55504 KB Output is correct
3 Correct 33 ms 55860 KB Output is correct
4 Correct 33 ms 56192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 54976 KB Output is correct
2 Correct 28 ms 55072 KB Output is correct
3 Correct 29 ms 55052 KB Output is correct
4 Correct 29 ms 55072 KB Output is correct
5 Correct 29 ms 55584 KB Output is correct
6 Correct 34 ms 56092 KB Output is correct
7 Correct 35 ms 56600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 55112 KB Output is correct
2 Correct 34 ms 55032 KB Output is correct
3 Correct 30 ms 54996 KB Output is correct
4 Correct 26 ms 55036 KB Output is correct
5 Correct 31 ms 55132 KB Output is correct
6 Correct 32 ms 55088 KB Output is correct
7 Correct 27 ms 55036 KB Output is correct
8 Correct 27 ms 55028 KB Output is correct
9 Correct 28 ms 55032 KB Output is correct
10 Correct 28 ms 55120 KB Output is correct
11 Correct 29 ms 55044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 55628 KB Output is correct
2 Correct 39 ms 56140 KB Output is correct
3 Correct 59 ms 56724 KB Output is correct
4 Correct 57 ms 57260 KB Output is correct
5 Correct 65 ms 57756 KB Output is correct
6 Correct 71 ms 58336 KB Output is correct
7 Correct 64 ms 60920 KB Output is correct
8 Correct 33 ms 55504 KB Output is correct
9 Correct 33 ms 55860 KB Output is correct
10 Correct 33 ms 56192 KB Output is correct
11 Correct 26 ms 54976 KB Output is correct
12 Correct 28 ms 55072 KB Output is correct
13 Correct 29 ms 55052 KB Output is correct
14 Correct 29 ms 55072 KB Output is correct
15 Correct 29 ms 55584 KB Output is correct
16 Correct 34 ms 56092 KB Output is correct
17 Correct 35 ms 56600 KB Output is correct
18 Correct 34 ms 55112 KB Output is correct
19 Correct 34 ms 55032 KB Output is correct
20 Correct 30 ms 54996 KB Output is correct
21 Correct 26 ms 55036 KB Output is correct
22 Correct 31 ms 55132 KB Output is correct
23 Correct 32 ms 55088 KB Output is correct
24 Correct 27 ms 55036 KB Output is correct
25 Correct 27 ms 55028 KB Output is correct
26 Correct 28 ms 55032 KB Output is correct
27 Correct 28 ms 55120 KB Output is correct
28 Correct 29 ms 55044 KB Output is correct
29 Correct 80 ms 58224 KB Output is correct
30 Correct 46 ms 55988 KB Output is correct
31 Correct 70 ms 58168 KB Output is correct
32 Correct 49 ms 56572 KB Output is correct
33 Correct 67 ms 58176 KB Output is correct
34 Correct 46 ms 57040 KB Output is correct
35 Correct 57 ms 58192 KB Output is correct
36 Correct 70 ms 57436 KB Output is correct
37 Correct 65 ms 58176 KB Output is correct
38 Correct 73 ms 57808 KB Output is correct
39 Correct 57 ms 58144 KB Output is correct