/ Randle /

记录详情

Time Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 5ms 384.0 KiB
#2 Accepted 6ms 364.0 KiB
#3 Accepted 4ms 256.0 KiB
#4 Accepted 3ms 256.0 KiB
#5 Accepted 146ms 512.0 KiB
#6 Accepted 157ms 640.0 KiB
#7 Accepted 128ms 640.0 KiB
#8 Accepted 129ms 2.375 MiB
#9 Accepted 130ms 640.0 KiB
#10 Accepted 132ms 624.0 KiB
#11 Accepted 207ms 1.875 MiB
#12 Accepted 223ms 2.074 MiB
#13 Accepted 221ms 1.984 MiB
#14 Accepted 334ms 2.812 MiB
#15 Accepted 262ms 2.191 MiB
#16 Accepted 323ms 2.043 MiB
#17 Accepted 584ms 2.184 MiB
#18 Accepted 657ms 2.793 MiB
#19 Accepted 530ms 2.727 MiB
#20 Time Exceeded ≥3008ms ≥3.016 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];
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]=e[i].l;
        	deep[e[i].to]=deep[u]+1;
        	dfs(e[i].to);
		}
}
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];
}
int get_lca(int x,int y)
{
	int i;
    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];
    if(x!=y)
    {
        for(i=(int)log2(n);i>=0;i--)
        {
            if(fa[x][i]!=fa[y][i])
            {
                x=fa[x][i];
                y=fa[y][i];
            }
        }
        x=fa[x][0];
    }
    return x;
}
ll work(int x,int y)
{
    ll a=0ll,b=0ll;
    int lca=get_lca(x,y),i;
    for(i=x;i!=lca;i=fa[i][0])
    {
        a=max(a,dis[i]);
    }
    for(i=y;i!=lca;i=fa[i][0])
    {
        b=max(b,dis[i]);
    }
    a=max(a,b);
    return a;
}
int main()
{
	//freopen("game13.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(work(m1,m2)==work(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 18:28:32
评测时间
2017-11-04 18:28:32
评测机
分数
95
总耗时
≥7198ms
峰值内存
≥3.016 MiB