답안 #537579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537579 2022-03-15T09:02:18 Z tqbfjotld Paths (RMI21_paths) C++14
12 / 100
184 ms 35916 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int K;

map<int,int > memo[100005];
vector<pair<int,int> > adjl[100005];

int dfs(int node, int pa, bool ig){
    if (memo[node].count(pa)) return memo[node][pa];
    int ans = 0;
    int ans2 = -999999999;
    int from1 = node;
    for (auto x : adjl[node]){
        if (ig && x.first==pa) continue;
        auto res = dfs(x.first,node,ig)+x.second;
        if (res>=ans){
            from1 = x.first;
            ans2 = ans;
            ans = res;
        }
        else if (res>=ans2){
            ans2 = res;
        }
    }
    if (ig){
        return memo[node][pa] = ans;
    }
    for (auto x : adjl[node]){
        if (x.first==from1) memo[node][x.first] = ans2;
        else memo[node][x.first] = ans;
    }
    memo[node][0] = ans;
    return memo[node][pa];
}

main(){
    int n;
    scanf("%lld%lld",&n,&K);
    for (int x = 0; x<n-1; x++){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        adjl[a].push_back({b,c});
        adjl[b].push_back({a,c});
    }
    for (int x = 1; x<=n; x++){
        auto res = dfs(x,0,x==1);
        int ans = res;
        printf("%lld\n",ans);
    }
}

Compilation message

Main.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%lld%lld",&n,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld%lld%lld",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 32284 KB Output is correct
2 Correct 166 ms 35916 KB Output is correct
3 Correct 109 ms 32176 KB Output is correct
4 Correct 156 ms 32248 KB Output is correct
5 Correct 184 ms 33656 KB Output is correct
6 Correct 154 ms 32080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -