QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425963#6112. Village PlanningHKOI0#Compile Error//C++202.3kb2024-05-30 19:41:562024-05-30 19:41:56

Judging History

你现在查看的是最新测评结果

  • [2024-05-30 19:41:56]
  • 评测
  • [2024-05-30 19:41:56]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

struct FunnyStruct {
    int n;
    vector<unordered_map<int, int>> g;
    
    vector<int> mx;
    vector<int> dp;

    int curAns;
    int bestU, bestV;

    void dfs(int u, int p) {
        vector<int> paths;
        for (auto& [v, w] : g[u]) {
            dp[u] = max(dp[u], dp[v]);
            paths.emplace_back(mx[v] + w);
        }

        sort(paths.rbegin(), paths.rend());
        if ((int)paths.size() >= 1) {
            mx[u] = paths[0];
            dp[u] = max(dp[u], paths[0]);
        }

        if ((int)paths.size() >= 2) {
            dp[u] = max(dp[u], paths[0] + paths[1]);
        }
    }

    void dfs2(int u, int p) {
        for (auto& [v, w] : g[u]) {
            if (v == p) continue;

            if ()
        }
    }

    FunnyStruct(int n, const vector<unordered_map<int, int>>& e) :
        n(n), g(e), mx(n), dp(n) {
            curAns = 0;
            bestU = bestV = INT_MIN;
    }

    pair<int, ll> furthest(int u) {

    }

    pair<int, int> solve() {

    }
};

void solve() {
    int n,k;
    cin>>n>>k;
    vector<unordered_map<int,int>> e(n);
    for(int i=0;i<n-1;i++) {
        int u,v,w;
        cin>>u>>v>>w;
        u--;
        v--;
        e[u].emplace(v);
        e[v].emplace(u);
    }

    {
        FunnyStruct g(n,e);
        auto [u,dis1]=g.furthest(0);
        auto [v,dis2]=g.furthest(u);
        cout<<dis2;
    }

    for(int i=1;i<=k;i++) {
        FunnyStruct g(n,e);
        auto [u0,v0]=g.solve();
        ll ans=0;
        int w=e[u0][v0];
        e[u0].erase(v0);
        e[v0].erase(u0);
        FunnyStruct ng(n,e);
        auto [u1,dis11]=ng.furthest(u0);
        auto [u2,dis12]=ng.furthest(u1);
        auto [v1,dis21]=ng.furthest(v0);
        auto [v2,dis22]=ng.furthest(v1);
        cout<<' '<<dis12+2+dis22;
        e[u1].emplace(v1,w);
        e[v1].emplace(u1,w);
    }
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    // cin >> T;
    while (T--) solve();
}

Details

answer.code: In member function ‘void FunnyStruct::dfs2(long long int, long long int)’:
answer.code:43:17: error: expected primary-expression before ‘)’ token
   43 |             if ()
      |                 ^
answer.code:44:9: error: expected primary-expression before ‘}’ token
   44 |         }
      |         ^
answer.code: In member function ‘std::pair<long long int, long long int> FunnyStruct::furthest(long long int)’:
answer.code:55:5: warning: no return statement in function returning non-void [-Wreturn-type]
   55 |     }
      |     ^
answer.code: In member function ‘std::pair<long long int, long long int> FunnyStruct::solve()’:
answer.code:59:5: warning: no return statement in function returning non-void [-Wreturn-type]
   59 |     }
      |     ^
In file included from /usr/include/c++/13/ext/alloc_traits.h:34,
                 from /usr/include/c++/13/bits/basic_string.h:39,
                 from /usr/include/c++/13/string:54,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:1:
/usr/include/c++/13/bits/alloc_traits.h: In instantiation of ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<const long long int, long long int>; _Args = {long long int&}; _Tp = std::__detail::_Hash_node<std::pair<const long long int, long long int>, false>; allocator_type = std::allocator<std::__detail::_Hash_node<std::pair<const long long int, long long int>, false> >]’:
/usr/include/c++/13/bits/hashtable_policy.h:2004:36:   required from ‘std::__detail::_Hashtable_alloc<_NodeAlloc>::__node_type* std::__detail::_Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&& ...) [with _Args = {long long int&}; _NodeAlloc = std::allocator<std::__detail::_Hash_node<std::pair<const long long int, long long int>, false> >; __node_ptr = std::allocator<std::__detail::_Hash_node<std::pair<const long long int, long long int>, false> >::value_type*]’
/usr/include/c++/13/bits/hashtable.h:307:35:   required from ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Scoped_node::_Scoped_node(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::__hashtable_alloc*, _Args&& ...) [with _Args = {long long int&}; _Key = long long int; _Value = std::pair<const long long int, long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<long long int>; _Hash = std::hash<long long int>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<false, false, true>; std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::__hashtable_alloc = std::_Hashtable<long long int, std::pair<const long long int, long long int>, std::allocator<std::pair<const long long int, long long int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::__hashtable_alloc]’
/usr/include/c++/13/bits/hashtable.h:2072:15:   required from ‘std::pair<typename std::__detail::_Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::iterator, bool> std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_M_emplace(std::true_type, _Args&& ...) [with _Args = {long long int&}; _Key = long long int; _Value = std::pair<const long long int, long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<long long int>; _Hash = std::hash<long long int>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<false, false, true>; typename std::__detail::_Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::iterator = std::__detail::_Insert_base<long long int, std::pair<const long long int, long long int>, std::allocator<std::pair<const long long int, long long int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator; typename _Traits::__constant_iterators = std::__detail::_Hashtable_traits<false, false, true>::__constant_iterators;...