답안 #875824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875824 2023-11-20T14:49:05 Z Mr_Ph Paths (RMI21_paths) C++17
19 / 100
600 ms 33700 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
map<pair<int,int>,int>mp;
vector<vi>adj;
int mx=0,lol=0;
vi xd;
void dfs(int node,int parent,int dis,vi path)
{
    //cout<<node<<" "<<parent<<endl;
    path.push_back(node);
    if(adj[node].sz==1)
    {
        if(dis>mx)
            lol=node,mx=dis,xd=path;
    }
    for(auto i:adj[node])
    {
        if(i!=parent)
        dfs(i,node,dis+mp[{node,i}],path);
    }
}
void preprocess() {}
void solve()
{
    int n,k;
    cin>>n>>k;
    adj.resize(n+1);
    for(int i=0; i<n-1; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        mp[ {a,b}]=c;
        mp[ {b,a}]=c;
    }
    map<pair<int,int>,int>mp1=mp;
    for(int root=1; root<=n; root++)
    {
        mp=mp1;
        int x=k;
        int ans=0;
        while(x--)
        {
            mx=0,lol=0;
            xd.clear();
            dfs(root,0,0,{});
            if(lol==0)
                break;
            ans+=mx;
            for(int i=1; i<xd.sz; i++)
            {
                mp[ {xd[i],xd[i-1]}]=0;
                mp[ {xd[i-1],xd[i]}]=0;
            }
        }
        cout<<ans<<endl;
    }
}
signed main()
{
    // freopen("meta_game_input.txt","r",stdin);
    // freopen("otput.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    preprocess();
    //bla();
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:70:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int i=1; i<xd.sz; i++)
      |                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 58 ms 504 KB Output is correct
4 Correct 61 ms 604 KB Output is correct
5 Correct 53 ms 348 KB Output is correct
6 Correct 43 ms 808 KB Output is correct
7 Correct 59 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 58 ms 504 KB Output is correct
4 Correct 61 ms 604 KB Output is correct
5 Correct 53 ms 348 KB Output is correct
6 Correct 43 ms 808 KB Output is correct
7 Correct 59 ms 344 KB Output is correct
8 Execution timed out 1040 ms 600 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 58 ms 504 KB Output is correct
4 Correct 61 ms 604 KB Output is correct
5 Correct 53 ms 348 KB Output is correct
6 Correct 43 ms 808 KB Output is correct
7 Correct 59 ms 344 KB Output is correct
8 Execution timed out 1040 ms 600 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1054 ms 33700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 58 ms 504 KB Output is correct
4 Correct 61 ms 604 KB Output is correct
5 Correct 53 ms 348 KB Output is correct
6 Correct 43 ms 808 KB Output is correct
7 Correct 59 ms 344 KB Output is correct
8 Execution timed out 1040 ms 600 KB Time limit exceeded
9 Halted 0 ms 0 KB -