求助90分
查看原帖
求助90分
298549
SIXIANG32楼主2020/5/2 21:18
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
vector<int>tree[500010];
int sum[500010],fath[500010];
int jump[500010][22],lo,w[10000];
inline int read()
{
    int ans=0;
    char ch=getchar();
    while (ch<'0' || ch>'9') ch=getchar();
    while (ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    return ans;
}
inline void write(int x)
{
    char f[200];
    int tmp=x>0?x:-x,cnt=0;
    if(x<0)putchar('-');
    while(tmp>0)f[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0)putchar(f[--cnt]);
    putchar('\n');
}
void ycl(int n)
{
    for(int p=1;p<=n;p++)
        tree[p].push_back(-1);
}
void link(int x,int y)
{
    tree[x].push_back(y);
    tree[y].push_back(x);
}
void dfs(int u,int fa)
{
    jump[u][0]=fa;
    fath[u]=fa;
    sum[u]=sum[fa]+1;
    for(int p=1;p<lo;p++)jump[u][p]=jump[jump[u][p-1]][p-1];
    for(int p=1;p<=tree[u].size()-1;p++)
    {
        if(tree[u][p]!=fa)
        {
            int k=tree[u][p];
            dfs(k,u);
        }
    }
}
int lca(int a,int b)
{
    if(a==b)return a;
    if(sum[a]<sum[b])swap(a,b);
    for(int p=lo;p>=0;p--)
        if(sum[jump[a][p]]>=sum[b])a=jump[a][p];
    if(a==b)return a;
    for(int p=lo;p>=0;p--)
        if(jump[a][p]!=jump[b][p])a=jump[a][p],b=jump[b][p];
    return jump[a][0];
}
int main() 
{
    int n,m,root,d_=0,w_=0;
    lo=20;
	n=read(),root=1;
    ycl(n);
    for(int p=1,x,y;p<=n-1;p++)
    x=read(),y=read(),link(x,y); 
    dfs(root,root);
    for(int p=1;p<=n-1;p++)
    	d_=max(d_,sum[p]),w[sum[p]]++;
    write(d_);
    for(int p=1;p<=d_;p++)
    	w_=max(w_,w[p]);
    write(w_);
    int x,y;
    x=read(),y=read();
    write(2*(sum[x]-sum[lca(x,y)])+sum[y]-sum[lca(x,y)]);
}

为什么只有九十分啊/kk求助QAQ

2020/5/2 21:18
加载中...