⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2374.cpp

📁 自己的ac代码 在acm.zju.edu.cn 上的题目
💻 CPP
字号:
#include<iostream>
#include<list>
using namespace std;
list < int> li[10002];
int n;
int h[10002];
int head[10002];
int ans=0;
int abs(int x)
{
	return x>0?x:-x;
}

int dfs(int t)
{
	int temp,c=0;
	while(!li[t].empty())
	{
		temp=li[t].back();li[t].pop_back();
		int ret=dfs(temp);
		c+=ret;
		ans+=abs(ret);
	}
	return c+h[t]-1;
}



int main()
{
	int i,j,k;
	int a,b,c;
	int he;
	while(scanf("%d",&n))
	{
		if(n==0)break;
		for(i=1;i<=n;i++)head[i]=i;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			h[a]=b;
			li[a].clear();
			for(j=1;j<=c;j++)
			{
				scanf("%d",&b);
				li[a].push_back(b);
				head[b]=a;
			}
		}
		he=1;
		while(head[he]!=he)he=head[he];
		ans=0;
		dfs(he);
		printf("%d\n",ans);
	}
	return 0;

}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -