/ Randle /

记录详情

Time Exceeded

/in/foo.cc: In function 'bool dfs(long long int, long long int, long long int, bool)':
/in/foo.cc:82:19: warning: unused variable 'ans' [-Wunused-variable]
  LL side=point[p],ans=0;
                   ^~~
# 状态 耗时 内存占用
#1 Accepted 4ms 376.0 KiB
#2 Accepted 4ms 2.25 MiB
#3 Accepted 4ms 2.375 MiB
#4 Accepted 4ms 2.375 MiB
#5 Accepted 447ms 512.0 KiB
#6 Accepted 431ms 2.25 MiB
#7 Accepted 416ms 2.461 MiB
#8 Accepted 418ms 512.0 KiB
#9 Accepted 396ms 512.0 KiB
#10 Accepted 448ms 2.355 MiB
#11 Accepted 2382ms 4.727 MiB
#12 Accepted 2493ms 4.488 MiB
#13 Accepted 2777ms 4.402 MiB
#14 Time Exceeded ≥3009ms ≥4.625 MiB
#15 Time Exceeded ≥3005ms ≥6.43 MiB
#16 Time Exceeded ≥3004ms ≥6.484 MiB
#17 Time Exceeded ≥3005ms ≥4.309 MiB
#18 Time Exceeded ≥3006ms ≥4.5 MiB
#19 Time Exceeded ≥3001ms ≥4.59 MiB
#20 Time Exceeded ≥3004ms ≥4.613 MiB

代码

#include<bits/stdc++.h>
#define LL long long
inline void read(LL&a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline void write(LL a)
{
	if(a<0){a=-a;putchar('-');}
	if(a>=10)write(a/10);
	putchar(a%10+'0');
}
inline bool get_order()
{
	char c=getchar();bool b;
	while(c<'a'||c>'z')c=getchar();
	if(c=='a')b=true;
	else b=false;
	while(c>='a'&&c<='z')c=getchar();
	return b;
}
#define pmaxn 6001
#define smaxn 210001
struct side
{
	LL from,to,len,next;
}s[smaxn];
inline const bool comp(const side&a,const side&b)
{
	if(a.len<b.len)return true;
	return false;
}
LL n,m,q,k=0;
LL next[pmaxn<<3],to[pmaxn<<3],len[pmaxn<<3];
LL point[pmaxn],d=0,big_side_a;
inline void add(LL a,LL b,LL c)
{
	next[++d]=point[a];
	point[a]=d;
	to[d]=b;
	len[d]=c;
}
LL belong[pmaxn];
inline LL check(LL a)
{
	if(a==belong[a])return a;
	return belong[a]=check(belong[a]);
}
inline void init()
{
	d=0;
	for(LL i=1;i<=n;i++){belong[i]=i;point[i]=0;}
}
inline LL least_tree()
{
	init();
	LL group=n-1,i=0;
	std::sort(s+1,s+1+k,comp);
	while(group)
	{
		++i;
		if(check(s[i].from)==check(s[i].to))continue;
		group--;
		belong[check(s[i].from)]=s[i].to;
		add(s[i].from,s[i].to,s[i].len);
		add(s[i].to,s[i].from,s[i].len);
	}
	return s[i].len;
}
bool vis[pmaxn];
LL ansa,ansb;
inline bool dfs(LL p,LL targ,LL has,bool which)
{
	vis[p]=true;
	if(p==targ){vis[p]=false;if(which)ansa=has;else ansb=has;return true;}
	LL side=point[p],ans=0;
	while(side)
	{
		if(!vis[to[side]])
			if(dfs(to[side],targ,std::max(has,len[side]),which)){vis[p]=false;return true;}
		side=next[side];
	}
	vis[p]=false;
	return false;
}
int main()
{
	read(n);read(m);
	LL u,v,l,m1,m2,b1,b2;
	for(LL i=1;i<=m;i++)
	{
		read(u);read(v);read(l);
		s[++k].from=u;s[k].to=v;s[k].len=l;
	}
	memset(vis,false,sizeof(vis));
	big_side_a=least_tree();
	read(q);
	while(q--)
	{
		if(get_order())
		{
			read(u);read(v);read(l);
			s[++k].from=u;s[k].to=v;s[k].len=l;
			if(s[k].len<big_side_a)big_side_a=least_tree();
		}
		else
		{
			read(m1);read(m2);
			dfs(m1,m2,-1,true);
			read(b1);read(b2);
			dfs(b1,b2,-1,false);
			if(ansa==ansb)puts("Baozika");
			else puts("madoka");
		}
	}
	return 0;
}

信息

递交者
类型
递交
题目
玩游戏(CQ直辖市noip模拟赛联考) T2
题目数据
下载
语言
C++
递交时间
2017-11-04 16:28:55
评测时间
2017-11-04 16:28:55
评测机
分数
65
总耗时
≥31265ms
峰值内存
≥6.484 MiB