QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584097#3736. Tree Intersection-xcxxx-WA 2ms13428kbC++141.4kb2024-09-23 08:26:332024-09-23 08:26:33

Judging History

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

  • [2024-09-23 08:26:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13428kb
  • [2024-09-23 08:26:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=(c=='-'?-1:f),c=getchar();while(isdigit(c))x=x*10+c-'0',c=getchar();return x*f;}
const int N=100005;
int n,fa[N],c[N],t[N],sum[N],ans[N],u[N],v[N];
vector<int> G[N];
map<int,int> cnt[N];
void dfs(int u,int f) {
    fa[u]=f;
    cnt[u][c[u]]++;
    for(int v:G[u]) if(v!=f) {
        dfs(v,u);
        // if(cnt[u].size()<cnt[v].size()) swap(cnt[u],cnt[v]);
        for(auto tmp:cnt[v]) {
            int x=tmp.first,c=tmp.second;
            cnt[u][x]+=c;
            if(cnt[u][x]==sum[x]) cnt[u].erase(cnt[u].find(x));
        }
        cnt[v].clear();
    }
    ans[u]=cnt[u].size();
}
signed main() {
    while(cin>>n) {
        memset(sum,0,sizeof(sum));
        for(int i=1;i<=n;i++) c[i]=t[i]=rd(),G[i].clear(),cnt[i].clear(),fa[i]=0;
        sort(t+1,t+1+n);
        int len=unique(t+1,t+1+n)-t-1;
        for(int i=1;i<=n;i++) c[i]=lower_bound(t+1,t+1+len,c[i])-t,sum[c[i]]++;
        for(int i=2;i<=n;i++) {
            int u=rd(),v=rd();
            printf("%d %d\n",u,v);
            G[u].push_back(v);
            G[v].push_back(u);
            ::u[i]=u,::v[i]=v;
        }
        dfs(1,0);
        for(int i=2;i<=n;i++) {
            if(fa[v[i]]==u[i]) swap(u[i],v[i]);
            printf("%d\n",ans[u[i]]);
        }
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 13428kb

input:

1000
449 327 407 122 15 572 311 4 824 142 103 491 449 383 593 549 233 355 586 231 197 198 308 268 206 305 66 499 322 300 761 101 857 284 668 22 221 51 234 159 9 147 253 220 171 202 264 34 233 716 758 460 9 174 138 456 378 6 390 127 263 291 486 246 15 425 346 892 803 556 787 670 204 90 155 289 628 42...

output:

119 623
996 909
271 212
174 868
786 867
493 197
32 537
162 9
663 322
997 871
854 839
281 386
95 865
47 52
633 884
259 515
968 515
879 352
734 613
484 160
783 403
563 496
17 427
132 189
150 405
618 710
285 533
861 439
110 57
603 678
170 962
39 634
666 254
450 692
297 200
426 405
183 11
776 443
689 46...

result:

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