1 solutions

  • 0
    @ 2026-4-6 20:08:45
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int N=2e5+10;
    int w[N];
    vector<int> g[N];
    bool st[N];
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>w[i];
    		int t;
    		cin>>t;
    		while(t--)
    		{
    			int x;
    			cin>>x;
    			g[i].push_back(x);//学习i之前需要先学习所有的x
    		}
    	}
    	st[n]=1;//最后一个一定是要学习的
    	LL ans=0;//学习的时间
    	for(int i=n;i>=1;i--)
    	{
    		if(st[i]) //需要学习当前的动作
    		{
    			ans+=w[i];
    			for(auto j:g[i]) //标记前面需要学习的内容
    			{
    				st[j]=1;
    			}
    		}
    	}
    	cout<<ans;
    }
    
    • 1

    Information

    ID
    2765
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    17
    Accepted
    3
    Uploaded By