/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 4ms 2.348 MiB
#2 Wrong Answer 4ms 2.375 MiB
#3 Wrong Answer 3ms 256.0 KiB
#4 Wrong Answer 5ms 2.25 MiB
#5 Wrong Answer 187ms 740.0 KiB
#6 Wrong Answer 174ms 2.5 MiB
#7 Wrong Answer 167ms 2.379 MiB
#8 Wrong Answer 166ms 2.496 MiB
#9 Wrong Answer 167ms 2.457 MiB
#10 Wrong Answer 174ms 2.461 MiB
#11 Wrong Answer 158ms 2.125 MiB
#12 Wrong Answer 166ms 3.766 MiB
#13 Wrong Answer 213ms 3.547 MiB
#14 Wrong Answer 298ms 3.496 MiB
#15 Wrong Answer 233ms 3.234 MiB
#16 Wrong Answer 235ms 2.926 MiB
#17 Wrong Answer 699ms 2.973 MiB
#18 Wrong Answer 743ms 3.82 MiB
#19 Wrong Answer 474ms 4.141 MiB
#20 Accepted 1798ms 3.871 MiB

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read_int()
{
	char ch=getchar();
	int x=0;
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
inline ll read_ll()
{
	char ch=getchar();
	ll x=0;
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int n,m,q;
struct edge1
{
    int x,y;
    ll l;
}e1[100005],e2[10005];
int cnt1=0,cnt2=0;

struct edge
{
	int to,nex;
	ll l;
}e[10005];
int point[5005],cnt=0;

int father[5005],deep[5005];
int fa[10005][16];
ll dis[10005][16];
inline void add1(int x,int y,ll l)
{
    e1[++cnt1].x=x;
    e1[cnt1].y=y;
    e1[cnt1].l=l;
}
inline void add2(int x,int y,ll l)
{
	e2[++cnt2].x=x;
    e2[cnt2].y=y;
    e2[cnt2].l=l;
}
inline void add(int x,int y,ll l)
{
    e[++cnt].to=y;
    e[cnt].nex=point[x];
    point[x]=cnt;
    e[cnt].l=l;
}
inline int find(int x)
{
    if(father[x]!=x) father[x]=find(father[x]);
    return father[x];
}
inline bool cmp(edge1 x,edge1 y)
{
	return x.l<y.l;
}
void Kruskal1()
{
	int i;
	sort(e1+1,e1+cnt1+1,cmp);
    for(i=1;i<=n;i++)
		father[i]=i;
    for(i=1;i<=m;i++)
    {
        int f1=find(e1[i].x);
		int f2=find(e1[i].y);
        if(f1!=f2)
		{
			add(e1[i].x,e1[i].y,e1[i].l);
			add(e1[i].y,e1[i].x,e1[i].l);
			add2(e1[i].x,e1[i].y,e1[i].l);
			father[f2]=f1;
		}
    }
}
void Kruskal2()
{
	int i,len=cnt2;
	sort(e2+1,e2+cnt2+1,cmp);
    for(i=1;i<=n;i++)
		father[i]=i;
	cnt2=0;
    for(i=1;i<=len;i++)
    {
        int f1=find(e2[i].x);
		int f2=find(e2[i].y);
        if(f1!=f2)
		{
			add(e2[i].x,e2[i].y,e2[i].l);
			add(e2[i].y,e2[i].x,e2[i].l);
			add2(e2[i].x,e2[i].y,e2[i].l);
			father[f2]=f1;
		}
    }
}
void dfs(int u)
{
	int i;
    for(i=point[u];i;i=e[i].nex)
        if(fa[u][0]!=e[i].to)
        {
        	fa[e[i].to][0]=u;
        	dis[e[i].to][0]=e[i].l;
        	deep[e[i].to]=deep[u]+1;
        	dfs(e[i].to);
		}
}
inline ll maxx(ll x,ll y)
{
	if(x>y) return x;
	else return y;
}
inline void init()
{
    for(int j=1;(1<<j)<=n;j++)
        for(int i=1;i<=n;i++)
        {
        	fa[i][j]=fa[fa[i][j-1]][j-1];
        	dis[i][j]=maxx(dis[i][j-1],dis[fa[i][j-1]][j-1]);
		}
            
}
ll get_lca_and_max(int x,int y)
{
	int i;
	ll ret=0;
    if(deep[x]>deep[y]) swap(x,y);
    int f=deep[y]-deep[x];
    for(i=0;(1<<i)<=f;i++)
        if(f&(1<<i))
            y=fa[y][i],ret=maxx(ret,dis[y][i]);
    if(x!=y)
    {
        for(i=(int)log2(n);i>=0;i--)
        {
            if(fa[x][i]!=fa[y][i])
            {
            	ret=maxx(ret,dis[x][i]);
            	ret=maxx(ret,dis[y][i]);
                x=fa[x][i];
                y=fa[y][i];
            }
        }
        ret=maxx(ret,dis[x][0]);
        ret=maxx(ret,dis[y][0]);
    }
    return ret;
}

int main()
{
	//freopen("game19.in","r",stdin);
	//freopen("game.out","w",stdout);
	int i,x,y,m1,m2,b1,b2;
	string s;
	long long z;
    n=read_int(),m=read_int();
    for(i=1;i<=m;i++)
    {
        x=read_int(),y=read_int(),z=read_ll();
        add1(x,y,z);
    }
    Kruskal1();
   	dfs(1);
   	init();
    q=read_int();
    while(q--)
    {
    	cin>>s;
    	if(s=="game")
    	{
    		m1=read_int(),m2=read_int();
    		b1=read_int(),b2=read_int();
 			if(get_lca_and_max(m1,m2)==get_lca_and_max(b1,b2))
				printf("Baozika\n");
			else
				printf("madoka\n");	
		}
		else
		{
			x=read_int(),y=read_int(),z=read_ll();
			if(z<e2[cnt2].l)
			{
				memset(point,0,sizeof(point));
				cnt=0;
				add2(x,y,z);
				Kruskal2();
				dfs(1);
				init();
			}
		}
    }
    return 0;
}

信息

递交者
类型
递交
题目
玩游戏(CQ直辖市noip模拟赛联考) T2
题目数据
下载
语言
C++
递交时间
2017-11-04 20:02:34
评测时间
2017-11-04 20:02:34
评测机
分数
5
总耗时
6075ms
峰值内存
4.141 MiB