Submission #51405938
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m; cin >> n >> m;
vector<pii> edges;
for (int i = 0; i < m; ++i) {
int u, v; cin >> u >> v;
--u; --v;
edges.pb({u, v});
}
vi w(n), a(n);
for (int i = 0; i < n; ++i) {
cin >> w[i];
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<vi> g(n), r(n);
for (auto [u, v] : edges) {
if (w[u] > w[v]) {
g[u].pb(v);
r[v].pb(u);
}
if (w[v] > w[u]) {
g[v].pb(u);
r[u].pb(v);
}
}
vector<int> deg(n);
queue<int> q;
for (int i = 0; i < n; ++i) {
deg[i] = sz(g[i]);
if (deg[i] == 0) q.push(i);
}
vi ops(n);
while (!q.empty()) {
int v = q.front(); q.pop();
ll best = 0;
vi dp(w[v], -1);
dp[0] = 0;
for (int u : g[v]) {
for (int i = w[v] - w[u] - 1; i >= 0; --i) {
if (dp[i] >= 0) {
dp[i + w[u]] = max(dp[i + w[u]], dp[i] + ops[u]);
best = max(best, dp[i + w[u]]);
}
}
}
ops[v] = ++best;
for (int u : r[v]) {
if (--deg[u] == 0) {
q.push(u);
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += a[i] * ops[i];
}
cout << ans;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Breakdown |
| User | richzli |
| Language | C++ 20 (gcc 12.2) |
| Score | 475 |
| Code Size | 1763 Byte |
| Status | AC |
| Exec Time | 30 ms |
| Memory | 4428 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 475 / 475 | ||||
| Status |
|
|
| 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 | 6 ms | 4264 KiB |
| 001.txt | AC | 3 ms | 4428 KiB |
| 002.txt | AC | 2 ms | 3672 KiB |
| 003.txt | AC | 2 ms | 3644 KiB |
| 004.txt | AC | 30 ms | 4096 KiB |
| 005.txt | AC | 7 ms | 3856 KiB |
| 006.txt | AC | 3 ms | 3932 KiB |
| 007.txt | AC | 2 ms | 3932 KiB |
| 008.txt | AC | 3 ms | 3908 KiB |
| 009.txt | AC | 2 ms | 4048 KiB |
| 010.txt | AC | 3 ms | 3940 KiB |
| 011.txt | AC | 3 ms | 3968 KiB |
| 012.txt | AC | 3 ms | 3968 KiB |
| 013.txt | AC | 3 ms | 4036 KiB |
| 014.txt | AC | 3 ms | 4016 KiB |
| 015.txt | AC | 3 ms | 4036 KiB |
| 016.txt | AC | 5 ms | 3872 KiB |
| 017.txt | AC | 7 ms | 3800 KiB |
| 018.txt | AC | 8 ms | 4100 KiB |
| 019.txt | AC | 8 ms | 3608 KiB |
| 020.txt | AC | 5 ms | 3876 KiB |
| 021.txt | AC | 11 ms | 4184 KiB |
| 022.txt | AC | 11 ms | 4172 KiB |
| 023.txt | AC | 12 ms | 4180 KiB |
| 024.txt | AC | 11 ms | 4192 KiB |
| 025.txt | AC | 11 ms | 4184 KiB |
| 026.txt | AC | 15 ms | 3720 KiB |
| 027.txt | AC | 13 ms | 3640 KiB |
| 028.txt | AC | 12 ms | 3724 KiB |
| 029.txt | AC | 7 ms | 3640 KiB |
| 030.txt | AC | 7 ms | 3724 KiB |
| 031.txt | AC | 5 ms | 3696 KiB |
| 032.txt | AC | 13 ms | 3744 KiB |
| 033.txt | AC | 10 ms | 3760 KiB |
| 034.txt | AC | 11 ms | 3684 KiB |
| 035.txt | AC | 7 ms | 3724 KiB |
| 036.txt | AC | 6 ms | 3720 KiB |
| 037.txt | AC | 5 ms | 3676 KiB |
| 038.txt | AC | 11 ms | 3640 KiB |
| 039.txt | AC | 10 ms | 3748 KiB |
| 040.txt | AC | 13 ms | 3676 KiB |
| 041.txt | AC | 6 ms | 3684 KiB |
| 042.txt | AC | 6 ms | 3824 KiB |
| 043.txt | AC | 6 ms | 3792 KiB |
| 044.txt | AC | 11 ms | 3684 KiB |
| 045.txt | AC | 10 ms | 3708 KiB |
| 046.txt | AC | 10 ms | 3828 KiB |
| 047.txt | AC | 5 ms | 3816 KiB |
| 048.txt | AC | 6 ms | 3788 KiB |
| 049.txt | AC | 6 ms | 3808 KiB |
| 050.txt | AC | 10 ms | 3700 KiB |
| 051.txt | AC | 10 ms | 3752 KiB |
| 052.txt | AC | 10 ms | 3820 KiB |
| 053.txt | AC | 5 ms | 3816 KiB |
| 054.txt | AC | 6 ms | 3948 KiB |
| 055.txt | AC | 5 ms | 3816 KiB |
| example0.txt | AC | 1 ms | 3424 KiB |
| example1.txt | AC | 1 ms | 3376 KiB |
| example2.txt | AC | 1 ms | 3620 KiB |