Educational Round 64 题解

前言:

这场太难了……我一个紫名只打出两题……(虽说感觉的确发挥不够好)

一群蓝绿名的dalao好像只打了两题都能升分的样子……

庆幸的是最后A出锅然后unr了>///<

写一波题解纪念这次失败的edu吧。


A

看起来很像sb题……实则细节巨多……

一开始分了六类就过了……

然后重测一遍就挂了……所以出题人做错自己出的题了?

注意特判三角形在圆里又在一个正方形的情况,会少一个点。


B

一开始想的是把相同的字母压一起,然后按ace...ybdf...z这样排。

然而出现一些毒瘤还是不行,然后就一直在想调换首位什么的,一直挂一直挂……

最后还是zz先切了……在奇数中选一个,偶数中选一个,它们不相邻,然后奇序列和偶序列之间插入这两个,就不会有这种问题了。


C

一眼贪心,一发WA。这么简单的正解没想到……

二分,每次把 $i(1le ile mid)$ 和 $n-mid+i$ 匹配看看行不行。


D

看起来是个树形dp,$f[u][0/1/2/3]$ 表示从下往上到 $u$ 分别是全 $0$,全 $1$,先 $0$ 再 $1$,先 $1$ 再 $0$ 的路有多少。

赛场上想出了然而打炸了……赛后又调出来了……。

具体转移看代码吧,应该能看懂的。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=400040;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
    char ch=getchar();ll x=0,f=0;
    while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return f?-x:x;
}
int n,el,head[maxn],to[maxn],w[maxn],nxt[maxn];
ll f[maxn][4],ans;
inline void add(int a,int b,int c){
    to[++el]=b;nxt[el]=head[a];head[a]=el;w[el]=c;
}
void dfs(int u,int F){
    ll s=0;
    for(int i=head[u];i;i=nxt[i]){
        int v=to[i];
        if(v==F) continue;
        dfs(v,u);
        if(w[i]){
            s+=f[u][0]*(f[v][1]+1);
            s+=f[u][1]*(f[v][0]+2*f[v][1]+f[v][2]+2);
            s+=f[u][2]*(f[v][1]+1);
            s+=f[v][0]+2*f[v][1]+f[v][2]+2;
            f[u][1]+=f[v][1]+1;
            f[u][2]+=f[v][2]+f[v][0];
        }
        else{
            s+=f[u][0]*(2*f[v][0]+f[v][1]+f[v][3]+2);
            s+=f[u][1]*(f[v][0]+1);
            s+=f[u][3]*(f[v][0]+1);
            s+=2*f[v][0]+f[v][1]+f[v][3]+2;
            f[u][0]+=f[v][0]+1;
            f[u][3]+=f[v][3]+f[v][1];
        }
    }
    ans+=s;
}
int main(){
    n=read();
    FOR(i,1,n-1){
        int u=read(),v=read(),w=read();
        add(u,v,w);add(v,u,w);
    }
    dfs(1,0);
    cout<<ans;
}
View Code

后面的,以后会做了再说吧……

原文地址:https://www.cnblogs.com/1000Suns/p/10801927.html