/ SB域 /

记录详情

Accepted

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

代码

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,ans1,ans2,sum;
int head1[600],head2[600],vis[600];
struct node
{
	int next;
	int to;
}road1[6000],road2[6000];
void dfs1(int now)
{
	vis[now]=1;
	for(int i=head1[now];i;i=road1[i].next)
	{
		if(!vis[road1[i].to])
		{
			ans1++;
		dfs1(road1[i].to);
		}
	}
}
void dfs2(int now)
{
	vis[now]=1;
	for(int i=head2[now];i;i=road2[i].next)
	{
		if(!vis[road2[i].to])
		{
			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;
    		memset(vis,0,sizeof(vis));
    		dfs1(i);
    		if(ans1>=(n+1)/2)sum++;
    }
    for(int i=1;i<=n;i++)
    {
    		ans2=0;
    		memset(vis,0,sizeof(vis));
    		dfs2(i);
    		if(ans2>=(n+1)/2)sum++;
    }
    cout<<sum;
	return 0;
}

信息

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