Submission #524804

# Submission time Handle Problem Language Result Execution time Memory
524804 2022-02-10T04:56:12 Z qwerasdfzxcl Mountains and Valleys (CCO20_day1problem3) C++14
2 / 25
13 ms 12492 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
vector<pair<int, int>> adj[500500];
int dist[500500];

void dfs(int s, int pa = -1){
    if (pa==-1) dist[s] = 0;
    else dist[s] = dist[pa] + 1;
    for (auto &v:adj[s]) if (v.first!=pa) dfs(v.first, s);
}

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i=0;i<m;i++){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        if (z!=1) continue;
        adj[x].emplace_back(y, z);
        adj[y].emplace_back(x, z);
    }

    dfs(0);
    dfs(max_element(dist, dist+n)-dist);
    printf("%d\n", (n-1)*2 - *max_element(dist, dist+n));
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d %d %d", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12476 KB Output is correct
2 Correct 10 ms 12492 KB Output is correct
3 Correct 13 ms 12456 KB Output is correct
4 Correct 10 ms 12444 KB Output is correct
5 Correct 10 ms 12448 KB Output is correct
6 Correct 11 ms 12320 KB Output is correct
7 Correct 10 ms 12492 KB Output is correct
8 Correct 9 ms 12452 KB Output is correct
9 Correct 9 ms 12492 KB Output is correct
10 Correct 12 ms 12452 KB Output is correct
11 Correct 10 ms 12376 KB Output is correct
12 Correct 10 ms 12364 KB Output is correct
13 Correct 10 ms 12448 KB Output is correct
14 Correct 10 ms 12492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12040 KB Output is correct
2 Correct 8 ms 11980 KB Output is correct
3 Correct 6 ms 12052 KB Output is correct
4 Correct 7 ms 12052 KB Output is correct
5 Correct 7 ms 12056 KB Output is correct
6 Correct 7 ms 12052 KB Output is correct
7 Correct 6 ms 11980 KB Output is correct
8 Correct 7 ms 11980 KB Output is correct
9 Correct 6 ms 12060 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Incorrect 6 ms 11980 KB Output isn't correct
12 Halted 0 ms 0 KB -