QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684901#6438. Crystalflycatch-up-from-behind#WA 1ms7980kbC++171.9kb2024-10-28 16:27:392024-10-28 16:27:39

Judging History

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

  • [2024-10-28 16:27:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7980kb
  • [2024-10-28 16:27:39]
  • 提交

answer

#include <bits/stdc++.h>
#define F(i,x,y) for(int i=(x);i<=(y);i++)
#define DF(i,x,y) for(int i=(x);i>=(y);i--)
#define ms(x,y) memset(x,y,sizeof(x))
#define SZ(x) (int)x.size()-1
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> pii;
template<typename T> void chkmax(T &x,T y){ x=max(x,y);}
template<typename T> void chkmin(T &x,T y){ x=min(x,y);}
template<typename T> void read(T &FF){
    FF=0;int RR=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') RR=-1;
    for(;isdigit(ch);ch=getchar()) FF=(FF<<1)+(FF<<3)+ch-48;
    FF*=RR;
}
const int N=100010;
const LL inf=1e18;
int n,a[N],t[N];
vector<int> G[N];
LL f[N],g[N];
void dfs(int u,int fa){
    LL tot=0;
    for(int v:G[u]) if(v!=fa) dfs(v,u),tot+=f[v];
    f[u]=0;
    for(int v:G[u]) if(v!=fa) chkmax(f[u],a[v]+tot);
    LL mx=-inf;
    for(int v:G[u]) if(v!=fa){
        if(t[v]==3) chkmax(f[u],tot-f[v]+g[v]+a[v]+mx);
        chkmax(mx,a[v]-g[v]+f[v]);
    }
    mx=-inf;
    DF(i,SZ(G[u]),0){
        int v=G[u][i];if(v==fa) continue;
        if(t[v]==3) chkmax(f[u],tot+a[v]+mx);
        chkmax(mx,a[v]-g[v]+f[v]);
    }
    // for(int v1:G[u]) if(v1!=fa)
    //     for(int v2:G[u]) if(v2!=fa&&v2!=u&&t[v2]==3){
    //         LL res=f[v2]+a[v2]+g[v1]+a[v1];
    //         for(int oth:G[u]) if(oth!=fa&&oth!=v1&&oth!=v2) res+=f[oth];
    //         chkmax(f[u],res);
    //     }
    g[u]=tot;
    // for(int v:G[u]) if(v!=fa) g[u]+=f[v];
}
void work(){
    read(n);
    F(i,1,n) read(a[i]);
    F(i,1,n) read(t[i]);
    F(i,1,n) G[i].clear();
    F(i,1,n-1){
        int x,y;read(x),read(y);
        G[x].pb(y),G[y].pb(x);
    }
    dfs(1,0);
    printf("%lld\n",f[1]+a[1]);
}
int main(){
    int T;read(T);
    while(T--) work();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7856kb

input:

2
5
1 10 100 1000 10000
1 2 1 1 1
1 2
1 3
2 4
2 5
5
1 10 100 1000 10000
1 3 1 1 1
1 2
1 3
2 4
2 5

output:

10101
10111

result:

ok 2 number(s): "10101 10111"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7980kb

input:

10
6
8 1 1 5 8 9
2 1 2 2 2 2
1 2
2 3
2 4
1 5
2 6
6
6 4 4 1 3 6
2 1 3 3 3 3
1 2
1 3
3 4
4 5
5 6
6
10 5 1 8 5 1
1 3 1 2 2 2
1 2
2 3
2 4
2 5
3 6
10
6 8 8 9 6 9 5 6 6 4
2 1 3 3 2 2 2 2 3 1
1 2
1 3
3 4
4 5
5 6
4 7
2 8
7 9
9 10
7
10 9 1 5 7 5 4
1 1 1 2 1 3 2
1 2
1 3
3 4
3 5
5 6
1 7
5
7 1 1 4 2
3 1 3 2 2
1...

output:

25
23
24
59
31
14
16
28
19
18

result:

wrong answer 2nd numbers differ - expected: '24', found: '23'