QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515297#7509. 01treeXY_ElevenWA 7ms6124kbC++236.0kb2024-08-11 16:55:332024-08-11 16:55:34

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 16:55:34]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:6124kb
  • [2024-08-11 16:55:33]
  • 提交

answer

#include <bits/stdc++.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<LL,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
// cLL mod=998244353,G=404;
cLL mod=1000000007ll;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
// mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
// int rnd(int l,int r) { return rd()%(r-l+1)+l; }

void main_init()
{

}
cint N=2.01e5;
int n;
vct <int> v[N];
char lstr[N];
short z1[N],z2[N];
void Add(LL &w1,const LL &w2)
{
    w1+=w2;
    if(w1>=mod) w1-=mod;
}
struct Node
{
    LL x,y;
    void put()
    {
        printf("> %lld,%lld\n",x,y);
    }
    friend void operator += (Node &w1,const Node &w2)
    {
        Add(w1.x,w2.x);
        Add(w1.y,w2.y);
    }
    friend Node operator + (const Node &w1,const Node &w2)
    {
        return {(w1.x+w2.x)%mod,(w1.y+w2.y)%mod};
    }
    friend void operator *= (Node &w1,const Node &w2)
    {
        w1.y=(w1.x*w2.y+w1.y*w2.x)%mod;
        mul(w1.x,w2.x);
    }
    friend Node operator * (const Node &w1,const Node &w2)
    {
        return {w1.x*w2.x%mod,(w1.x*w2.y+w1.y*w2.x)%mod};
    }
};
Node f[N][2],g[N];
void dfs(int p,int fa)
{
    if(fa) v[p].erase(find(all(v[p]),fa));
    int m=sz(v[p]);
    vct <array<array<Node,2>,2> > d1(m<<1|1),d1_(m<<1|1);
    for(auto &i:d1) For(k1,0,1) For(k2,0,1) i[k1][k2]={0ll,0ll};
    For(k1,0,1)
    {
        exc(!(z1[p]>>k1&1));
        For(k2,0,1)
        {
            exc(!(z2[p]>>k2&1));
            add(d1[m][k1^k2][k1].x,1ll);
            // printf("%d:%d\n",p,k1^k2);
        }
    }
    for(auto p2:v[p])
    {
        dfs(p2,p);
        for(auto &i:d1_) For(k1,0,1) For(k2,0,1) i[k1][k2]={0ll,0ll};
        For_(i,1,m<<1) For(k1,0,1) For(k2,0,1)
        {
            d1_[i+1][!k1][k2]+=d1[i][k1][k2]*f[p2][k2];
            d1_[i-1][!k1][k2]+=d1[i][k1][k2]*f[p2][!k2];
            d1_[i][k1][k2]+=d1[i][k1][k2]*g[p2];
        }
        swap(d1,d1_);
    }
    For(k,0,1) For(i,0,m<<1) Add(d1[i][1][k].y,d1[i][1][k].x);
    g[p]=(d1[m][0][0]+d1[m][0][1])+(m>0?(d1[m+1][0][0]+d1[m+1][0][1]):(Node){0ll,0ll});
    // printf("%d: m=%d\n",p,m);
    For(k,0,1) f[p][k]=d1[m][1][k]+(m>0?(d1[m-1][1][k]+d1[m+1][1][!k]):(Node){0ll,0ll})+(m>1?d1[m+2][1][!k]:(Node){0ll,0ll});
    // printf("%d:\n",p); f[p][0].put(); f[p][1].put();
}
void main_solve()
{
    inint(n);
    For(i,1,n) v[i].clear();
    For_(i,1,n)
    {
        int x,y; inpr(x,y);
        v[x].pb(y),v[y].pb(x);
        For(k,0,1) f[i][k]={0ll,0ll};
        g[i]={0ll,0ll};
    }
    scanf("%s",lstr+1); For(i,1,n) z1[i]=(lstr[i]=='?'?3:(1<<lstr[i]-'0'));
    scanf("%s",lstr+1); For(i,1,n) z2[i]=(lstr[i]=='?'?3:(1<<lstr[i]-'0'));
    int rt=min(1,n);
    dfs(rt,0);
    outll(g[rt].y);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out1.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 6124kb

input:

3
2
1 2
00
11
3
1 2
2 3
???
???
3
1 2
2 3
??1
0?0

output:

1
16
1

result:

ok 3 number(s): "1 16 1"

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 5864kb

input:

1000
23
1 2
1 3
1 4
2 5
5 6
4 7
3 8
4 9
8 10
8 11
8 12
1 13
7 14
10 15
7 16
7 17
5 18
18 19
12 20
9 21
21 22
6 23
00?10?0000??1?00111?010
011??1?10?01?110?0??101
6
1 2
1 3
1 4
4 5
3 6
000?10
1???01
25
1 2
2 3
2 4
4 5
5 6
2 7
4 8
5 9
7 10
8 11
11 12
5 13
11 14
3 15
6 16
14 17
1 18
4 19
6 20
4 21
5 22...

output:

0
19
0
1444
81
14
0
28
376
1062
46
2
0
839
464
590
122496
0
18209
1
0
17098
616
4
13019
0
0
5572852
354
3
0
1077
0
1186
63
72
11
408253
3994
5405
7
0
2
122
38110
19880
26340
40696
9556
35
0
25209
0
31775
143175
0
2336592
636695
4248
188
2622
189
7
79
226
2
13592
8002
287
34
1771
0
133192
1296
11
178...

result:

wrong answer 1st numbers differ - expected: '53545', found: '0'