悬赏!!!萌新刚学oi1e-90秒,求助大佬

P3806 【模板】点分治 1

Timing @ 2019-07-16 13:40:45

样例可以过,评测爆零全MLE,应该是递归爆栈,但真的不知道那炸掉了,

```cpp using namespace std; int main() {} #include<bits/stdc++.h> #define rt register int #define gt getchar() #define INF 10000000 const int _ = 1e5 + 10; namespace OI { struct _Main { int n,m,root,Size,f[_],siz[_],dis[_],sum[_],plus[1010]; int exist[_],judge[_],down[_]; int cnt,head[_],ver[_<<1],nxt[_<<1],edge[_<<1]; bool used[_]; inline void add (int u, int v, int w) { ver[++cnt] = v; nxt[cnt] = head[u]; edge[cnt] = w; head[u] = cnt; } inline void Get_Root (int u, int fa) { f[u] = 0, siz[u] = 1; rt i; for (i = head[u]; i; i = nxt[i]){ int v = ver[i]; if(used[v] or v == fa) continue; Get_Root(v,u); f[u] = max(f[u],siz[v]); siz[u] += siz[v]; } f[u] = max(f[u],Size - siz[u]); if(f[u] < f[root]) root = u; } inline void Get_Dis (int u, int fa) { sum[++sum[0]] = dis[u]; rt i; for (i = head[u]; i; i = nxt[i]){ int v = ver[i]; if(used[v] or v == fa) continue; dis[v] = dis[u] + edge[i]; Get_Dis(v,u); } } inline void Calc (int u) { rt p = 0, i, j, k; for (i = head[u]; i; i = nxt[i]){ int v = ver[i]; if(used[v]) continue; sum[0] = 0; dis[v] = edge[i]; Get_Dis(v,u); for (j = sum[0]; j; --j) for (k = 1; k <= m; ++k) if(plus[k] >= sum[j]) exist[k] |= judge[plus[k] - sum[j]]; for (j = sum[0]; j; --j) down[++p] = sum[j], judge[sum[j]] = 1; } for (i = 1; i <= p; ++i) judge[down[i]] = 0; } inline void solve (int u) { used[u] = (judge[0] = 1); Calc(u); rt i; for (i = head[u]; i; i = nxt[i]){ int v = ver[i]; if(used[i]) continue; Size = siz[v]; f[root = 0] = INF; Get_Root(v,0); solve(root); } } _Main() { read(n); read(m); rt i, u, v, w; for (i = 1; i < n; ++i){ read(u); read(v); read(w); add(u,v,w); add(v,u,w); } for (i = 1; i <= m; ++i) read(plus[i]); f[root] = Size = n; Get_Root(1,0); solve(root); for (i = 1; i <= m; ++i){ if(exist[i]) puts("AYE"); else puts("NAY"); } } template <typename Type> inline void read(Type &x) { char s, f = 1; while(!isdigit(s = gt)) f = (s == '-') ? -1 : 1; x = s ^ 48; while(isdigit(s = gt)) x = (x<<1) + (x<<3) + (s ^ 48); x *= f; } } std; } ``` 感谢进来的巨佬们,~~明年你们都AK NOI~~

by Timing @ 2019-07-16 13:41:22

额。。。\LaTeX为什么炸了QAQ


by syh233 @ 2019-07-16 13:43:50

qndmx


by Nickel_Angel @ 2019-07-16 13:46:40

某人的码风……

换个码风试试


by Timing @ 2019-07-16 13:48:04

@Nickel_Angel 构造函数没毛病啊,,,


by Timing @ 2019-07-16 13:48:33

@Nickel_Angel 除了我偶尔会忘写main函数


by Nickel_Angel @ 2019-07-16 13:53:02

exist和judge是不是应该开大一些(许多)


by Timing @ 2019-07-16 13:54:44

@Nickel_Angel 我已经MLE了啊。。。


by dblark @ 2019-07-16 13:56:45

@Timing 悬赏有问题:

error: lvalue required as left operand of assignment

by Nickel_Angel @ 2019-07-16 13:57:59

@Timing 数组越界也会MLE


by Timing @ 2019-07-16 13:58:06

@dblark 蛤?莫非(29300 += 41) %=13 == 0被你发现了?


| 下一页