QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#533075#9165. Petrol stationsDimash#0 28ms17940kbC++232.1kb2024-08-25 16:50:082024-08-25 16:50:08

Judging History

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

  • [2024-08-25 16:50:08]
  • 评测
  • 测评结果:0
  • 用时:28ms
  • 内存:17940kb
  • [2024-08-25 16:50:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
    
typedef long long ll;
const int  N = 1e5 + 12, MOD = (int)1e9 + 7;

int n,a[N],k;
bool rt[N];
ll pref[N];
vector<int> g[N];
ll cost(ll l,ll r) {
    if(l > r) swap(l,r);
    return pref[r] - pref[l];
}
bool rev = false;
int s[N];
ll res[N];
void dfs(int v) {
    s[v] = 1;
    for(int to:g[v]) {
        dfs(to);
        s[v] += s[to];
    }
    if(rev) {
        res[v] += (s[v] - 1) * 1ll * (v - 1);
    } else {
        res[v] += (s[v] - 1) * 1ll * (n - v );
    }
    // if(v == 5) {
    //     cout << s[v] - 1 << ' ' << rev << "x\n";
    // }
    // res[v] += s[v] - 1;
}
int id[N];
void solve() {
    for(int i = 1;i <= n;i++) {
        g[i].clear();
        rt[i] = 1;
        pref[i] = pref[i - 1] + a[i];
    }
    for(int i = 1,it = 1; i <= n; i++) {
        while(it <= n && cost(id[i],id[it]) <= k) {
            it++;
        }
        if(it <= n) {
            g[id[it - 1]].push_back(id[i]);
            rt[id[i]] = 0;
        }
    }
    for(int i = 1; i <= n; i++) {
        if(rt[i]) {
            dfs(i);
        }
    }
}
int bf[N];
vector<pair<int,int>> gr[N];
vector<int> ord;
void go(int v,int pr = -1) {
    ord.push_back(v);
    for(auto [to,w]:gr[v]) {
        if(to != pr) {
            a[to] = w;
            go(to,v);
        }
    }
}
void test() {
    cin >> n >> k;
    for(int i = 1; i <= n - 1; i++) {
        int x,y,w;
        cin >> x >> y >> w;
        x++;
        y++;
        gr[x].push_back({y,w});
        gr[y].push_back({x,w});
    }
    for(int i = 1;i <= n;i++) {
        if((int)gr[i].size() == 1) {
            go(i);
            break;
        }
    }
    for(int i = 0;i < n;i++) {
        id[i + 1] = ord[i];
    }
    // return;
    solve();
    rev = 1;
    reverse(id + 1,id + n + 1);
    solve();
    for(int i = 1; i <= n; i++) {
        cout << res[i] << '\n';
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

750 918
159 63 18
573 310 105
135 400 57
618 27 113
41 265 24
99 576 61
242 85 109
490 88 0
626 721 0
407 446 0
78 644 124
346 198 17
541 504 147
543 423 24
302 450 25
397 344 80
129 607 76
474 59 140
30 10 29
375 260 1
404 81 0
658 695 153
450 100 92
532 249 10
597 151 133
739 714 0
212 345 85
558 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 2nd lines differ - expected: '96', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 8
Accepted
time: 1ms
memory: 5696kb

input:

2 1
0 1 1

output:

0
0

result:

ok 2 lines

Test #14:

score: 0
Wrong Answer
time: 27ms
memory: 17940kb

input:

70000 1
50913 18377 1
33894 11911 1
61940 7863 1
61602 33470 1
26341 35575 1
30813 50301 1
2994 67214 1
38527 61714 1
37381 3396 1
43274 14867 1
59352 12066 1
68877 40750 1
44756 43671 1
57921 17977 1
10879 47719 1
26878 13556 1
27329 23697 1
45109 11513 1
21307 12312 1
27202 27807 1
7250 14810 1
27...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '2128187656', found: '0'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 28ms
memory: 13844kb

input:

69973 4
44281 27162 1
15299 61302 1
19250 66379 1
45970 65938 1
23683 4445 2
62232 40589 1
37028 58991 2
58769 32024 0
41860 69672 2
14687 10058 2
7874 6780 2
60579 37047 2
739 4096 2
53137 22114 2
35060 21464 0
42597 11591 2
68051 23473 2
61458 35690 2
38719 6601 2
57406 26025 1
38192 41521 0
47941...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '769608', found: '0'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%