```
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
#define LF(x) fixed << setprecision(x)
typedef pair<int, int> pii;
#define endl "\n"
struct edge {
int to, next;
}e[1000009];
pair<int,int> head[10009]; int degree[10009];
int cnt = 0;
void add(int a, int b) {
++cnt;
e[cnt].next = head[a].first;
e[cnt].to = b;
head[a].first = cnt;
degree[b]++;
}
int mx = 0;
void dfs(int u,int sum) {
if (sum +head[u].second >= mx&&mx!=0 )
return;//剪枝
if (u==1 ){
mx = max(mx, sum+head[u].second);
}
for (int i = head[u].first; i != 0; i = e[i].next) {
dfs(e[i].to, sum +head[u].second);
}
}
void solve() {
int n; cin >> n;
for (int i = 0; i < n; i++) {
int a, b, w; cin >> a >>w;
head[a].second = w;
cin >> b;
while (b) {
add(a, b);
cin >> b;
}
}
for (int i = 1; i <= n; i++) {
if (degree[i] == 0)
dfs(i, 0);
}
cout << mx << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
```
加了剪枝之后结果只有20分了,那位大佬能指点一二呢??
by Exile_Code @ 2023-09-01 16:38:44