Submission #2095929


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
const long long mod = 1000000007;
const int maxn = 100100;
vector<int> tr[maxn];
int a[maxn], b[maxn], c[maxn], sz[maxn];
long long s[maxn], dw[maxn], res[maxn];
int n;
void solve(int cur, int pr = -1){
    sz[cur] = 1;
    dw[cur] = 0;
    for(int id : tr[cur]){
        int nxt = cur ^ c[id];
        if(nxt == pr) continue;
        solve(nxt, cur);
        sz[cur] += sz[nxt];
    }
    for(int id : tr[cur]){
        int nxt = cur ^ c[id];
        if(nxt == pr) continue;
        int den = ((n - sz[nxt] + 1) - 1 - sz[nxt]);
        if(den == 0){
            assert(0);
            res[id] = (s[cur] - dw[nxt]) / (sz[nxt]);
        } else {
            res[id] = (s[nxt] - s[cur]) / den;
        }
        dw[cur] += dw[nxt] + (sz[nxt]) * res[id];
    }
}
int main(){
    scanf("%d", &n);
    for(int e = 0; e < n - 1; e++){
        scanf("%d %d", a + e, b + e); c[e] = a[e] ^ b[e];
        tr[a[e]].push_back(e);
        tr[b[e]].push_back(e);
    }
    for(int e = 1; e <= n; e++) scanf("%lld", s + e);
    solve(1);
    for(int e = 0; e < n - 1; e++) cout << res[e] << endl;
	return 0;
}

Submission Info

Submission Time
Task D - Ancient Tree Record
User FMota
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1183 Byte
Status RE
Exec Time 220 ms
Memory 18048 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:32:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:34:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", a + e, b + e); c[e] = a[e] ^ b[e];
                                     ^
./Main.cpp:38:53: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(int e = 1; e <= n; e++) scanf("%lld", s + e);
                                                     ^

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 0 / 300 200 / 200 0 / 300
Status
AC × 2
RE × 1
AC × 7
RE × 7
AC × 11
AC × 33
RE × 15
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt
Subtask2 00_example_02.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s3_27.txt, s3_28.txt, s3_29.txt, s3_30.txt, s3_31.txt, s3_32.txt, s3_33.txt, s3_34.txt, s3_35.txt, s3_36.txt, s3_37.txt, s3_38.txt, s3_39.txt, s3_40.txt, s3_41.txt, s3_42.txt, s3_43.txt, s3_44.txt, s3_45.txt
Case Name Status Exec Time Memory
00_example_01.txt RE 102 ms 4608 KB
00_example_02.txt AC 2 ms 4480 KB
00_example_03.txt AC 2 ms 4480 KB
s1_01.txt RE 126 ms 11776 KB
s1_02.txt AC 165 ms 15360 KB
s1_03.txt RE 103 ms 4864 KB
s1_04.txt AC 135 ms 13568 KB
s1_05.txt AC 23 ms 5888 KB
s1_06.txt AC 204 ms 18048 KB
s1_07.txt RE 150 ms 17024 KB
s1_08.txt AC 200 ms 18048 KB
s1_09.txt RE 99 ms 4480 KB
s1_10.txt RE 101 ms 4480 KB
s1_11.txt AC 2 ms 4480 KB
s1_12.txt RE 101 ms 4480 KB
s1_13.txt AC 2 ms 4480 KB
s2_14.txt AC 108 ms 8188 KB
s2_15.txt AC 154 ms 9592 KB
s2_16.txt AC 191 ms 10744 KB
s2_17.txt AC 192 ms 10744 KB
s2_18.txt AC 197 ms 10744 KB
s2_19.txt AC 191 ms 10744 KB
s2_20.txt AC 2 ms 4480 KB
s2_21.txt AC 2 ms 4480 KB
s2_22.txt AC 2 ms 4480 KB
s2_23.txt AC 2 ms 4480 KB
s3_24.txt AC 116 ms 8064 KB
s3_25.txt AC 162 ms 9216 KB
s3_26.txt AC 9 ms 4736 KB
s3_27.txt AC 139 ms 8448 KB
s3_28.txt AC 24 ms 5120 KB
s3_29.txt AC 208 ms 10368 KB
s3_30.txt AC 210 ms 10496 KB
s3_31.txt AC 211 ms 10368 KB
s3_32.txt RE 154 ms 13824 KB
s3_33.txt AC 220 ms 16896 KB
s3_34.txt AC 204 ms 10744 KB
s3_35.txt AC 202 ms 10744 KB
s3_36.txt RE 99 ms 4480 KB
s3_37.txt AC 2 ms 4480 KB
s3_38.txt AC 2 ms 4480 KB
s3_39.txt AC 2 ms 4480 KB
s3_40.txt RE 127 ms 7680 KB
s3_41.txt RE 137 ms 8704 KB
s3_42.txt RE 101 ms 4736 KB
s3_43.txt RE 147 ms 9728 KB
s3_44.txt RE 148 ms 9856 KB
s3_45.txt RE 148 ms 9728 KB