답안 #273958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
273958 2020-08-19T08:00:32 Z 반딧불(#5107) Mountains and Valleys (CCO20_day1problem3) C++17
1 / 25
7000 ms 12928 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
vector<pair<int, int> > link[500002];
int depth[500002];
bool used[2000002];

int edgeX[2000002], edgeY[2000002], edgeZ[2000002];
int ans = INT_MAX, maX, root;
int lengthSum;

void dfs(int x, int par = -1){
    if(par==-1) root = x;
    for(auto &y: link[x]){
        if(y.first != par && used[y.second] && y.first != root && depth[y.first]==0){
            depth[y.first] = depth[x] + edgeZ[y.second];
            dfs(y.first, x);
        }
    }
}

void calc(){
    for(int k=0; k<n; k++) depth[k] = 0;
    dfs(0);
    maX = max_element(depth, depth+n) - depth;
    for(int k=1; k<n; k++){
        if(depth[k]==0) return;
        depth[k] = 0;
    }
    dfs(maX);
    ans = min(ans, 2*lengthSum-*max_element(depth, depth+n));
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++){
        int x, y, w;
        scanf("%d %d %d", &x, &y, &w);
        link[x].push_back({y, i}), link[y].push_back({x, i});
        edgeX[i] = x, edgeY[i] = y, edgeZ[i] = w;

        if(edgeZ[i] == 1) used[i] = 1, lengthSum++;
    }

    for(int i=1; i<=m; i++){
        if(edgeZ[i] == 1) continue;
        used[i] = 1, lengthSum+=edgeZ[i];
        for(int j=1; j<=m; j++){
            if(edgeZ[j] != 1) continue;
            used[j] = 0;
            lengthSum--;
            calc();
            used[j] = 1, lengthSum++;
        }
        used[i] = 0, lengthSum-=edgeZ[i];
    }
    calc();

    printf("%d", ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         scanf("%d %d %d", &x, &y, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12112 KB Output is correct
18 Incorrect 9 ms 12032 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 7019 ms 12928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12112 KB Output is correct
18 Incorrect 9 ms 12032 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12112 KB Output is correct
18 Incorrect 9 ms 12032 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12112 KB Output is correct
18 Incorrect 9 ms 12032 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12112 KB Output is correct
18 Incorrect 9 ms 12032 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
3 Correct 11 ms 12160 KB Output is correct
4 Correct 11 ms 12232 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 11 ms 12148 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12032 KB Output is correct
10 Correct 13 ms 12032 KB Output is correct
11 Correct 11 ms 12032 KB Output is correct
12 Correct 11 ms 12032 KB Output is correct
13 Correct 10 ms 12064 KB Output is correct
14 Correct 10 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12112 KB Output is correct
18 Incorrect 9 ms 12032 KB Output isn't correct
19 Halted 0 ms 0 KB -