QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#112421#6107. One Pathyukino_yukinoshitaWA 2ms4740kbC++141.6kb2023-06-11 17:32:522023-06-11 17:32:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-11 17:32:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4740kb
  • [2023-06-11 17:32:52]
  • 提交

answer

#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i=j, r##i=k; i<=r##i; ++i)
#define ROF(i,j,k) for(int i=j, l##i=k; i>=l##i; --i)
inline int read (void) {
  int x = 0, f = 1, ch = getchar();
  while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
  while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}
using ll = long long;
inline ll _max (ll p, ll q) { return p > q ? p : q; }
const int maxn = 2005;
int tot_edge, head[maxn], to[maxn<<1], link[maxn<<1], cost[maxn<<1];
inline void add_edge (int x, int y, int c) {
  to[++tot_edge] = y;
  cost[tot_edge] = c;
  link[tot_edge] = head[x];
  head[x] = tot_edge;
}
ll f[maxn][maxn][3], g[maxn][3]; int K, sz[maxn];
void dfs (int x, int fa=0) {
  sz[x] = 1;
  for(int now=head[x]; now; now=link[now]) {
    if(to[now] == fa) continue;
    dfs (to[now], x);
    FOR(i,0,sz[x]-1) FOR(j,0,sz[to[now]]-1) {
      FOR(k,0,2) g[i+j+1][k] = _max (g[i+j+1][k], f[x][i][k] + cost[now] + f[to[now]][j][2]);
      FOR(k1,0,2) FOR(k2,0,2) if(k1 + k2 <= 2)
        g[i+j][k1+k2] = _max (g[i+j][k1+k2], f[x][i][k1] + f[to[now]][j][k2] + (k2 == 1) * cost[now]);
    }
    std::swap (f[x], g); memset (g, 0, sizeof(g));
    sz[x] += sz[to[now]];
    FOR(i,0,sz[x]-1) FOR(j,1,2)
      f[x][i][j] = _max (f[x][i][j], f[x][i][j-1]);
  }
}
int main (void) {
  int n = read(); K = read();
  FOR(i,2,n) {
    int x = read(), y = read(), c = read();
    add_edge (x, y, c);
    add_edge (y, x, c);
  }
  dfs (1);
  FOR(i,0,K) printf("%lld%c", f[1][i][2], i==K?10:32);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3648kb

input:

5 1
1 3 2
4 5 4
3 4 3
2 3 7

output:

14 16

result:

ok 2 number(s): "14 16"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3764kb

input:

7 2
1 2 4
2 3 6
2 4 2
4 5 5
2 6 1
4 7 3

output:

13 20 21

result:

ok 3 number(s): "13 20 21"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 4740kb

input:

50 2000
3 34 1
37 39 58720256
17 24 14680064
28 39 1
25 38 1
21 29 1
3 30 1
26 36 1
5 48 14336
4 22 1
26 41 1
41 44 1
5 14 1
23 25 28672
40 41 224
27 39 1
4 20 7340032
7 47 939524096
11 46 114688
30 49 3584
34 44 1
7 35 1
10 29 1
27 33 29360128
16 36 56
8 28 1
13 38 57344
34 45 896
15 35 469762048
1...

output:

1409286145 1761607683 1849688069 1871708167 1877213193 1878589451 1878933517 1879019535 1879041041 1879046419 1879047765 1879048103 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 1879048160 187...

result:

wrong answer 51st numbers differ - expected: '1879048160', found: '0'