Submission #50415768


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

void solve(std::istream& is, std::ostream& os) {
    Num n, m;
    is >> n >> m;

    Edges edges_fwd(n);
    for(Num i{0}; i<m; ++i) {
        Num u, v;
        is >> u >> v;
        --u;
        --v;
        edges_fwd[u].push_back(v);
        edges_fwd[v].push_back(u);
    }

    Vec ws(n);
    for(auto&& w : ws) {
        is >> w;
    }

    Vec aset(n);
    for(auto&& a : aset) {
        is >> a;
    }

    std::vector<std::pair<Num, Num>> ordered;
    for(Num from{0}; from<n; ++from) {
        ordered.push_back(std::make_pair(ws.at(from), from));
    }
    std::ranges::sort(ordered);

    Num total {0};
    Vec degs(n, 0);
    for(const auto& [nw, from] : ordered) {
        const auto from_w = ws.at(from);
        Vec dp(from_w, -1000000000000000000LL);
        dp.at(0) = 0;

        for(const auto& to : edges_fwd[from]) {
            const auto to_w = ws.at(to);
            auto next = dp;

            for(Num i{0}; i<from_w; ++i) {
                Num wsum = i + to_w;
                if (wsum >= from_w) {
                    break;
                }
                next.at(wsum) = std::max(next.at(wsum), dp.at(i) + degs.at(to));
            }

            std::swap(dp, next);
        }

        const auto deg = 1 + (*std::ranges::max_element(dp));
        total += aset.at(from) * deg;
        degs.at(from) = deg;
    }

    os << total << "\n";
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task F - Breakdown
User zettsut
Language C++ 20 (gcc 12.2)
Score 475
Code Size 2107 Byte
Status AC
Exec Time 32 ms
Memory 4200 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 59
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 24 ms 3948 KiB
001.txt AC 22 ms 4200 KiB
002.txt AC 3 ms 3764 KiB
003.txt AC 18 ms 3784 KiB
004.txt AC 32 ms 4140 KiB
005.txt AC 7 ms 3696 KiB
006.txt AC 5 ms 3988 KiB
007.txt AC 5 ms 4024 KiB
008.txt AC 5 ms 4028 KiB
009.txt AC 5 ms 4076 KiB
010.txt AC 5 ms 4016 KiB
011.txt AC 5 ms 3988 KiB
012.txt AC 5 ms 4080 KiB
013.txt AC 5 ms 3988 KiB
014.txt AC 5 ms 3984 KiB
015.txt AC 5 ms 4176 KiB
016.txt AC 15 ms 3856 KiB
017.txt AC 14 ms 3876 KiB
018.txt AC 24 ms 4104 KiB
019.txt AC 13 ms 3740 KiB
020.txt AC 18 ms 3824 KiB
021.txt AC 32 ms 4024 KiB
022.txt AC 31 ms 4084 KiB
023.txt AC 31 ms 4024 KiB
024.txt AC 30 ms 4020 KiB
025.txt AC 30 ms 4028 KiB
026.txt AC 14 ms 3704 KiB
027.txt AC 13 ms 3780 KiB
028.txt AC 14 ms 3712 KiB
029.txt AC 7 ms 3720 KiB
030.txt AC 6 ms 3752 KiB
031.txt AC 4 ms 3908 KiB
032.txt AC 13 ms 3752 KiB
033.txt AC 14 ms 3740 KiB
034.txt AC 16 ms 3796 KiB
035.txt AC 7 ms 3704 KiB
036.txt AC 7 ms 3940 KiB
037.txt AC 6 ms 3672 KiB
038.txt AC 14 ms 3796 KiB
039.txt AC 17 ms 3792 KiB
040.txt AC 13 ms 3704 KiB
041.txt AC 7 ms 3988 KiB
042.txt AC 7 ms 3644 KiB
043.txt AC 6 ms 3792 KiB
044.txt AC 14 ms 3792 KiB
045.txt AC 17 ms 3924 KiB
046.txt AC 18 ms 3816 KiB
047.txt AC 7 ms 3996 KiB
048.txt AC 7 ms 3840 KiB
049.txt AC 8 ms 3868 KiB
050.txt AC 16 ms 3780 KiB
051.txt AC 18 ms 3872 KiB
052.txt AC 17 ms 3904 KiB
053.txt AC 6 ms 3856 KiB
054.txt AC 8 ms 3968 KiB
055.txt AC 7 ms 3864 KiB
example0.txt AC 1 ms 3536 KiB
example1.txt AC 1 ms 3520 KiB
example2.txt AC 1 ms 3484 KiB