QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#409558#7502. Painting the Roadsgrass8cow#WA 1ms4028kbC++171.7kb2024-05-12 11:10:412024-05-12 11:10:41

Judging History

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

  • [2024-05-12 11:10:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4028kb
  • [2024-05-12 11:10:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
int U[5010],V[5010],C[5010],W[5010];
vector<int>g[5010];
#define pb push_back
int fa[5010],d[5010],ds[5010];
void dfs(int x){
    for(int i:g[x]){
        int v=U[i]^V[i]^x;if(fa[x]==v)continue;
        fa[v]=x,dfs(v),ds[x]^=ds[v];
        if(ds[v]!=C[i])d[v]=1,ds[x]^=1;
    }
}
int p[5010];
int og[5010],sl[5010],sr[5010];
int dp[5010][10100];
const int Z=5000,I=1e9+10;
int fz[10010],fz2[10100];
inline void ad(int &x,int y){if(x>y)x=y;}
void dfs2(int x){
    for(int i:g[x])if((U[i]^V[i]^x)!=fa[x])dfs2(U[i]^V[i]^x);
    int c=og[x]-d[x];
    sl[x]=sr[x]=c,fz[Z+c]=0;
    for(int ii:g[x]){
        int v=U[ii]^V[ii]^x;if(v==fa[x])continue;
        int tl=sl[x]+sl[v],tr=sr[x]+sr[v];
        for(int i=tl;i<=tr;i++)fz2[i+Z]=I;
        for(int i=sl[x];i<=sr[x];i++)
        for(int j=sl[v];j<=sr[v];j++)
        ad(fz2[i+j+Z],fz[i+Z]+dp[v][j+Z]+abs(j)*W[ii]);
        for(int i=tl;i<=tr;i++)fz[i+Z]=fz2[i+Z];
        sl[x]=tl,sr[x]=tr;
    }
    if(sl[x]>-1){for(int j=-1;j<sl[x];j++)fz[Z+j]=I;sl[x]=-1;}
    for(int i=sr[x];i>0;i--)ad(fz[Z+i-2],fz[Z+i]);
    for(int i=sl[x];i<=sr[x];i++)dp[x][Z+i]=fz[Z+i];
}
void sol(){
    for(int i=1;i<=n;i++)g[i].clear(),fa[i]=0,ds[i]=0,og[i]=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++)scanf("%d%d%d%d",&U[i],&V[i],&W[i],&C[i]),g[U[i]].pb(i),g[V[i]].pb(i);
    dfs(1);d[1]=ds[1];
    for(int i=1;i<=m;i++)scanf("%d",&p[i]),d[p[i]]^=1,og[p[i]]++;
    int sx=0;
    for(int i=1;i<=n;i++)sx+=d[i];if(sx>m){puts("-1");return;}
    dfs2(1);
    printf("%d\n",dp[1][Z]);
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4028kb

input:

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

output:

3
9
21
-1
1000000010

result:

wrong answer 5th numbers differ - expected: '42', found: '1000000010'