답안 #1052658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052658 2024-08-10T18:36:49 Z presko Paths (RMI21_paths) C++14
0 / 100
1 ms 2396 KB
#include<iostream>
#include<vector>
#define MAXN 2010
using namespace std;
vector<int> edges[MAXN];
int cost[MAXN][MAXN];
int cost2[MAXN][MAXN];
int dfs(int curr, int parent)
{
    int maxx=0;
    for(int i=0;i<edges[curr].size();i++)
    {
        int next=edges[curr][i];
        if(next==parent)continue;
        int val=cost[curr][next];
        maxx=max(maxx,val+dfs(next,curr));
    }
    return maxx;
}
bool clean(int curr, int parent, int len, int lim)
{
    if(len==lim)return 1;
    for(int i=0;i<edges[curr].size();i++)
    {
        int next=edges[curr][i];
        if(next==parent)continue;
        int val=cost[curr][next];
        if(clean(next,curr,len+val,lim))
        {
            cost[curr][next]=0;
            cost[next][curr]=0;
            return 1;
        }
    }
    return 0;
}
int main()
{
    int n,k;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        int a,b,x;
        cin>>a>>b>>x;
        edges[a].push_back(b);
        edges[b].push_back(a);
        cost[a][b]=x;
        cost[b][a]=x;
        cost2[a][b]=x;
        cost2[b][a]=x;
    }
    for(int i=1;i<=n;i++)//n
    {
        int ans=0;
        for(int j=1;j<=k;j++)
        {
            int res=dfs(i,0);
            ans+=res;
            clean(i,0,0,res);
        }
        for(int a=1;a<=n;a++)
        {
            for(int b=1;b<=n;b++)cost[a][b]=cost2[a][b];
        }
        cout<<ans<<"\n";
    }
}

Compilation message

Main.cpp: In function 'int dfs(int, int)':
Main.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<edges[curr].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'bool clean(int, int, int, int)':
Main.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<edges[curr].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -