답안 #676284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676284 2022-12-30T06:37:32 Z Do_you_copy Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
40 ms 11040 KB
//Then
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 1;
//const int Mod = 1e9 + 7;
//const int inf =
int n, m;
bool visited[maxN];
vector <int> adj[maxN];
pii far;
int depth[maxN];
void dfs(int u, int p){
    depth[u] = depth[p] + 1;
    visited[u] = 1;
    far = max(far, make_pair(depth[u], u));
    for (int i: adj[u]){
        if (i == p) continue;
        dfs(i, u);
    }
}


void Init(){
    cin >> n >> m;
    for (int i = 1; i <= m; ++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        if (visited[i]) continue;
        far = {0, 0};
        dfs(i, 0);
        dfs(far.se, 0);
        ans += far.fi;
    }
    cout << ans;
}

#define debug
#define taskname "test"
signed main(){
    faster
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
        #ifndef debug
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        #endif // debug
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3412 KB Output is correct
2 Correct 12 ms 4096 KB Output is correct
3 Correct 18 ms 4720 KB Output is correct
4 Correct 23 ms 5336 KB Output is correct
5 Correct 33 ms 6020 KB Output is correct
6 Correct 36 ms 6548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 11040 KB Output is correct
2 Correct 4 ms 3204 KB Output is correct
3 Correct 7 ms 3668 KB Output is correct
4 Correct 9 ms 4164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 5 ms 3284 KB Output is correct
6 Correct 8 ms 3932 KB Output is correct
7 Correct 12 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2676 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2680 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2684 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 2 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3412 KB Output is correct
2 Correct 12 ms 4096 KB Output is correct
3 Correct 18 ms 4720 KB Output is correct
4 Correct 23 ms 5336 KB Output is correct
5 Correct 33 ms 6020 KB Output is correct
6 Correct 36 ms 6548 KB Output is correct
7 Correct 29 ms 11040 KB Output is correct
8 Correct 4 ms 3204 KB Output is correct
9 Correct 7 ms 3668 KB Output is correct
10 Correct 9 ms 4164 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2676 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 5 ms 3284 KB Output is correct
16 Correct 8 ms 3932 KB Output is correct
17 Correct 12 ms 4564 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2676 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2680 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2684 KB Output is correct
27 Correct 3 ms 2644 KB Output is correct
28 Correct 2 ms 2680 KB Output is correct
29 Correct 39 ms 6544 KB Output is correct
30 Correct 8 ms 4180 KB Output is correct
31 Correct 27 ms 6604 KB Output is correct
32 Correct 14 ms 4804 KB Output is correct
33 Correct 32 ms 6532 KB Output is correct
34 Correct 24 ms 5320 KB Output is correct
35 Correct 31 ms 6404 KB Output is correct
36 Correct 26 ms 5660 KB Output is correct
37 Correct 29 ms 6456 KB Output is correct
38 Correct 40 ms 6124 KB Output is correct
39 Correct 29 ms 6432 KB Output is correct