/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 40ms 96.309 MiB
#2 Accepted 43ms 96.309 MiB
#3 Accepted 109ms 96.309 MiB
#4 Accepted 172ms 96.434 MiB
#5 Accepted 713ms 96.375 MiB
#6 Accepted 709ms 96.309 MiB
#7 Accepted 614ms 96.379 MiB
#8 Accepted 586ms 96.312 MiB
#9 Accepted 714ms 96.383 MiB
#10 Accepted 658ms 96.312 MiB

代码

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack> 
#include <ctime>

using namespace std;

#define MAXN 5010

int n,m;
int x,y;
int son[MAXN][MAXN];
bool isuse[MAXN];
int ans[MAXN];
int now;
queue <int> q;

int main()
{
	memset(son,0,sizeof(son));
	memset(ans,0,sizeof(ans));
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&x,&y);
		son[x][++son[x][0]]=y;
	}
	while(!q.empty())q.pop();
	for(int i=1;i<=5000;++i)
	{
		memset(isuse,true,sizeof(isuse));
		isuse[i]=false;
		q.push(i);
		while(!q.empty())
		{
			now=q.front();
			q.pop();
			for(int j=1;j<=son[now][0];++j)
				if(isuse[son[now][j]])
				{
					isuse[son[now][j]]=false;
					++ans[i];
					q.push(son[now][j]);
				}
		}
	}
	scanf("%d",&m);
	for(int i=1;i<=m;++i)
	{
		scanf("%d",&x);
		if(x>5000)printf("0 0\n");
			else printf("%d %d\n",son[x][0],ans[x]);
	}
	return 0;
}

信息

递交者
类型
递交
题目
附庸 T4
题目数据
下载
语言
C++
递交时间
2017-09-22 19:53:09
评测时间
2017-09-22 19:53:09
评测机
分数
100
总耗时
4363ms
峰值内存
96.434 MiB