QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354610#5094. 小 H 分糖果ANIG0 4ms7848kbC++231.2kb2024-03-15 18:41:332024-03-15 18:41:34

Judging History

This is the latest submission verdict.

  • [2024-03-15 18:41:34]
  • Judged
  • Verdict: 0
  • Time: 4ms
  • Memory: 7848kb
  • [2024-03-15 18:41:33]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
int n,m,w[N],fa[N],dep[N],res,lth,mk[N];
vector<int>p[N];
void dfs(int x){
    mk[x]=1;
    for(auto c:p[x]){
        if(mk[c])continue;
        dfs(c);
        fa[c]=x;
    }
    mk[x]=0;
}
int solve(int a,int b){
    lth=0;res=0;
    memset(mk,0,sizeof(mk));
    if(dep[a]>dep[b])swap(a,b);
    while(dep[b]>dep[a])res+=w[b],mk[b]=1,b=fa[b],lth++;
    while(a!=b)res+=w[a]+w[b],mk[a]=mk[b]=1,a=fa[a],b=fa[b],lth+=2;
    res+=w[a];mk[a]=1;lth++;
    return res;
}
signed main(){
    cin>>n>>m;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        p[x].push_back(y);
        p[y].push_back(x);
    }
    dfs(1);
    for(int i=1;i<=n;i++)cin>>w[i];
    while(m--){
        int op,x,y,k;
        cin>>op>>x>>y;
        if(op==1){
            w[x]=y;
        }else{
            cin>>k;
            int res=solve(x,y),ans=0;
            for(int i=1;i<=n;i++)if(!mk[i])ans+=w[i]*w[i];
            if(k<res){
                k=res-k;
                int t=k/lth,ts=k-t*lth;
                ans+=t*t*(lth-ts)+(t+1)*(t+1)*ts;
            }
            cout<<ans<<endl;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 7848kb

input:

866 841
1 864
4 153
9 559
10 410
11 336
12 417
14 666
18 241
21 184
22 849
23 40
25 783
26 189
28 329
29 216
31 864
34 581
40 131
42 625
45 744
47 723
50 633
51 447
52 454
53 88
55 619
60 259
62 680
67 126
72 371
73 742
80 196
81 536
82 647
85 254
87 172
88 489
93 708
94 227
95 340
96 7
7 91
97 594
...

output:

281987861
283792655
276402342
288949631
275967924
291808368
281522481
289114289
290675718
286622922
287570532
286106445
282249691
289598117
284914679
284522676
285845011
285421214
282719631
280177305
285521825
277699462
286197421
289281052
284648611
278793021
291841166
292115577
292039120
290388505
...

result:

wrong answer 1st lines differ - expected: '285125508', found: '281987861'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

input:

87080 98363
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52...

output:

-3172481905770064441
6081472970522666261
3584128024889698703
-6577530481154251090
2187257286374209673
-4649566132996668366
-7211015478323554797
-2729943335828673556
5715081650848515799
405799460963267173
-5889937866029823273
2144831282531371981
-6151658481199738783
933942990520016052
-31567736274561...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%