/ SB域 /

记录详情

Time Exceeded

/in/foo.cc: In function 'int main()':
/in/foo.cc:30:6: warning: unused variable 'sum1' [-Wunused-variable]
  int sum1[6000]={0},sum2[6000]={0};
      ^~~~
/in/foo.cc:30:21: warning: unused variable 'sum2' [-Wunused-variable]
  int sum1[6000]={0},sum2[6000]={0};
                     ^~~~
# 状态 耗时 内存占用
#1 Accepted 2ms 204.0 KiB
#2 Wrong Answer 2ms 204.0 KiB
#3 Accepted 1ms 204.0 KiB
#4 Accepted 2ms 204.0 KiB
#5 Accepted 1ms 204.0 KiB
#6 Time Exceeded ≥1004ms ≥388.0 KiB
#7 Accepted 2ms 328.0 KiB
#8 Wrong Answer 96ms 328.0 KiB
#9 Wrong Answer 6ms 328.0 KiB
#10 Wrong Answer 2ms 200.0 KiB

代码

#include<iostream>
using namespace std;
int n,m,ans1,ans2,sum;
int head1[600],head2[600];
struct node
{
	int next;
	int to;
}road1[6000],road2[6000];
void dfs1(int now)
{
	for(int i=head1[now];i;i=road1[i].next)
	{
		ans1++;
		dfs1(road1[i].to);
	}
}
void dfs2(int now)
{
	for(int i=head2[now];i;i=road2[i].next)
	{
		ans2++;
		dfs2(road2[i].to);
	}
}
int main()
{
	cin>>n>>m;
	//node road1[6000],road2[6000];
	int sum1[6000]={0},sum2[6000]={0};
	int k1=0,k2=0;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		road1[++k1].to=y;
		road1[k1].next=head1[x];
		head1[x]=k1;
		road2[++k2].to=x;
		road2[k2].next=head2[y];
		head2[y]=k2;
	}
    for(int i=1;i<=n;i++)
    {
    		ans1=0;
    		dfs1(i);
    		if(ans1>=(n+1)/2)sum++;
    }
    for(int i=1;i<=n;i++)
    {
    		ans2=0;
    		dfs2(i);
    		if(ans2>=(n+1)/2)sum++;
    }
    cout<<sum;
	return 0;
}

信息

递交者
类型
递交
题目
珍珠
题目数据
下载
语言
C++
递交时间
2019-03-27 14:02:27
评测时间
2019-03-27 14:02:27
评测机
分数
50
总耗时
≥1122ms
峰值内存
≥388.0 KiB