双向边?单向边?

P3252 [JLOI2012] 树

以至于开map各种存链的起点终点,改到怀疑人生,最后读题,卒
by fletmer @ 2018-09-22 23:25:34


@[fleetingtime](/space/show?uid=44669) 给你看看我的代码吧,错误自己找,~~我要写作业~~ ```cpp #include <bits/stdc++.h> #define in(a) scanf ("%d", &a) #define mem(a, b) memset (a, b, sizeof (a))using namespace std; using namespace std; struct node { int data; vector < int > son; } nod[100001]; int n, S; int ans = 0; void dfs(int cen, int sum, int pos) { if (sum == S) { ans ++; return ; } //这个判断之所以要加是因为可能存在此节点无子根,但值够了 for (int i = 0; i < nod[pos].son.size(); i ++) { if (sum+nod[nod[pos].son[i]].data == S) { ans ++; continue; } if (sum+nod[nod[pos].son[i]].data > S) continue; if (cen == n-1) continue; dfs (cen+1, sum+nod[nod[pos].son[i]].data, nod[pos].son[i]); } return ; } int main() { in(n), in(S); for (int i = 0; i < n; i ++) scanf ("%d", &nod[i].data); for (int i = 0; i < n-1; i ++) { int a, b; in(a), in(b); a--, b--; nod[a].son.push_back(b); } for (int i = 0; i < n; i ++) dfs(0, nod[i].data, i); printf ("%d", ans); return 0; } ```
by tocek_shiki @ 2018-09-22 23:28:20


@[fff团666](/space/show?uid=49562) 然而看你的干啥,有什么用?
by fletmer @ 2018-09-23 12:02:04


@[fleetingtime](/space/show?uid=44669) ??? 您不是要找bug吗
by tocek_shiki @ 2018-09-23 12:11:42


。。只是吐槽你看不出来吗
by fletmer @ 2018-09-23 12:19:50


@[fff团666](/space/show?uid=49562) 不过还是很感谢您的,您的码风很好
by fletmer @ 2018-09-23 12:20:44


@[fleetingtime](/space/show?uid=44669) 不。用。谢。。 ~~(莫名gg~~ 另附:现在我的马蜂也。。。。
by tocek_shiki @ 2018-09-23 13:48:35


|