洛谷P1113

洛谷P1113

#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define int __int128
typedef unsigned long long ull;
using ld = long double;
inline int read();
inline void write(int);
#define inf 0x3f3f3f3f         // 0x7fffffff 2147483647
#define INF 0x3f3f3f3f3f3f3f3f // 0x7fffffffffffffff 9223372036854775807
#define lowbit(x) ((x) & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define PII pair<int, int>
#define fi first
#define se second
#define mem(x, y) memset(x, y, sizeof(x))
#define endl '\n'
const double PI = acos(-1.0);
#define eps 1e-7
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cerr << #x << ": " << x << endl;
const int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int maxn = 1e6 + 5;
const int mod = 998244353;
const int N = 10011;
int t[N], in[N], dp[N];
int ans;
vector<int> edge[N];
void solve()
{
    int n = read();
    rep(i,1,n)
    {
        int x = read();
        t[x] = read();
        int y = read();
        while(y)
        {
            edge[y].pb(x);
            in[x]++;
            y = read();
        }
    }

    queue<int> q;
    rep(i,1,n)
    {
        if(!in[i])
        {
            q.push(i);
            dp[i] = t[i];
        }
    }
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        for (int i = 0; i < (int)edge[now].size();i++)
        {
            int ne = edge[now][i];
            dp[ne] = max(dp[ne], dp[now] + t[ne]);
            in[ne]--;
            if(!in[ne])
                q.push(ne);
        }
    }
    
    rep(i, 1, n)
        ans = max(ans, dp[i]);
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // cout << fixed;
    // cout.precision(18);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}

inline int read()
{
    register int x = 0, f = 1;
    register char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = (x << 1) + (x << 3) + (ch ^ '0');
        ch = getchar();
    }
    return x * f;
}

inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
    return;
}

  • 13
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值