Submission #994428

# Submission time Handle Problem Language Result Execution time Memory
994428 2024-06-07T15:35:39 Z De3b0o Paths (RMI21_paths) C++14
19 / 100
600 ms 2388 KB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*n)
#define rc (2*n+1)

using namespace std;

ll fp(ll x , ll y)
{
    if(y==0)
        return 1;
    ll z = fp(x,y/2);
    if(y&1)
        return z*z*x;
    else
        return z*z;
}

int sqrot(ll x)
{
    int l = 0 , r = INT_MAX;
    while(l<=r)
    {
        if(mid*mid>=x)
            r=mid-1;
        else
            l=mid+1;
    }
    return r+1;
}

ll cel(ll x , ll y)
{
    return x/y + bool(x%y);
}

string tb(ll x)
{
    string s = "";
    while(x>0)
    {
        if(x&1)
            s+='1';
        else
            s+='0';
        x/=2;
    }
    while(s.size()<60)
        s+='0';
    return s;
}

ll fb(string s)
{
    ll x = 0;
    ll c = 1;
    for(int8_t i = 0 ; 60>i ; i++)
    {
        if(s[i]=='1')
            x+=c;
        c*=2;
    }
    return x;
}

ll n , k;
vector<pll> adj[1009];
ll ans[1009];
vector<pll> a[1009];

void dpt(ll x , ll p)
{
    set<pair<ll,pll>> s;
    for(auto it : adj[x])
    {
        if(it.F==p)
            continue;
        dpt(it.F,x);
        ll y = it.S;
        if(!a[it.F].empty())
            y+=a[it.F][0].F;
        s.in({y,{it.F,1}});
    }
    while(!s.empty()&&a[x].size()<k)
    {
        auto it = s.end();
        it--;
        a[x].pb({it->F,it->S.F});
        ans[x]+=it->F;
        if(it->S.S<a[it->S.F].size())
            s.in({a[it->S.F][it->S.S].F,{it->S.F,it->S.S+1}});
        s.erase(it);
    }
}

int main()
{
    d3
    cin >> n >> k;
    for(int i = 0 ; n-1>i ; i++)
    {
        ll x , y , c;
        cin >> x >> y >> c;
        adj[x].pb({y,c});
        adj[y].pb({x,c});
    }
    for(int i = 1 ; n>=i ; i++)
    {
        for(int j = 1 ; n>=j ; j++)
            a[j].clear();
        memset(ans,0,sizeof(ans));
        dpt(i,0);
        cout << ans[i] << "\n";
    }
}

Compilation message

Main.cpp: In function 'void dpt(long long int, long long int)':
Main.cpp:98:34: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   98 |     while(!s.empty()&&a[x].size()<k)
      |                       ~~~~~~~~~~~^~
Main.cpp:104:19: warning: comparison of integer expressions of different signedness: 'const long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         if(it->S.S<a[it->S.F].size())
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 128 ms 2388 KB Output is correct
9 Execution timed out 712 ms 1616 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 128 ms 2388 KB Output is correct
9 Execution timed out 712 ms 1616 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 128 ms 2388 KB Output is correct
9 Execution timed out 712 ms 1616 KB Time limit exceeded
10 Halted 0 ms 0 KB -