QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292478#7118. Closing TimeAuroraH4568 133ms47544kbC++142.6kb2023-12-28 05:55:292024-04-28 08:05:44

Judging History

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

  • [2024-04-28 08:05:44]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:133ms
  • 内存:47544kb
  • [2023-12-28 05:55:31]
  • 评测
  • 测评结果:8
  • 用时:125ms
  • 内存:46592kb
  • [2023-12-28 05:55:29]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define SZ(X) (int)(X.size())
#define MAX 200005
#define pii pair <int,int>
#define node first
#define wei second
using namespace std;

int caseNum;
int nodeNum, cityA, cityB;
ll lim;
vector <pii> edge[MAX];
ll dist[MAX][2];
int ans;
int a, b, c;

vector <pair<ll,ll>> opt; // b (cost for reachable from both), a (cost for reachable from one)
multiset <ll, greater <ll>> ms; // chosen costs
ll curCost;
int curAns;

void reset(){
    for (int i = 0; i < nodeNum; i++){
        edge[i].clear();
        dist[i][0] = dist[i][1] = 0;
    }
    ans = 0;
    
    opt.clear();
    ms.clear();
    curCost = 0;
    curAns = 0;
}

void dfs(int cur, int par, bool which){ // for each node, find distance from the two cities
    for (pii nex : edge[cur]){
        if (nex.node == par) continue;
        dist[nex.node][which] = dist[cur][which] + nex.wei;
        dfs(nex.node, cur, which);
    }
}

void moveBack(){
    while (!ms.empty() && curCost > lim){
        curCost -= *ms.begin();
        curAns--;
        ms.erase(ms.begin());
    }
}

void msDelete(ll val){
    auto it = ms.find(val);
    if (it != ms.end()) ms.erase(it);
}

void enumOverlap(){ // check options for overlap
    for (int i = 0; i < nodeNum; i++){ // assume each node -> reachable to at most one city
        opt.push_back({max(dist[i][0], dist[i][1]), min(dist[i][0], dist[i][1])});
        ms.insert(opt.back().second);
        curCost += opt.back().second;
        curAns++;
    }
    moveBack();
    ans = curAns;
    /*sort(opt.begin(), opt.end()); // sort by max distance

    for (pii o : opt){ // each node before o -> reachable to at least one city
        curCost += o.second;
        curAns++;
        msDelete(o.second);
        ms.insert(o.first-o.second);
        moveBack();
        if (curCost > lim) return;
        ans = max(ans, curAns);
    }*/
}

int max_score(int N, int A, int B, ll limit, vector <int> U, vector <int> V, vector <int> W){
    nodeNum = N;
    cityA = A;
    cityB = B;
    lim = limit;
    
    reset();
    for (int i = 0; i < nodeNum-1; i++){
        edge[U[i]].push_back({V[i], W[i]});
        edge[V[i]].push_back({U[i], W[i]});
    }
    dfs(cityA, -1, 0);
    dfs(cityB, -1, 1);

    enumOverlap();
    
    return ans;
}


/*int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout << max_score(4, 0, 3, 20, {0, 1, 2}, {1, 2, 3}, {18, 1, 19}) << "\n";
    
    cout << max_score(7, 0, 2, 10,
                      {0, 0, 1, 2, 2, 5}, {1, 3, 2, 4, 5, 6}, {2, 3, 4, 2, 5, 3}) << "\n";
     
    return 0;
}*/


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 121ms
memory: 41504kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 31011 61157 8517583098
31011 129396 964383
1655 129396 331139
1655 191487 566483
110385 191487 865248
43212 110385 542661
43212 81682 13766
81682 91774 546589
91774 124706 780638
124706 175650 118706
10421 175650 615314
10421 151953 436270
140430 151...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
451

result:

ok 

Test #2:

score: 0
Accepted
time: 133ms
memory: 47544kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 97133 170892 35489415917
114511 170892 730058
34783 114511 435023
34783 47301 562314
47301 162600 457629
44856 162600 365133
44856 133801 83016
117539 133801 124222
117539 128719 199821
77871 128719 703141
77871 133155 624331
7211 133155 138691
7211 ...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
650

result:

ok 

Test #3:

score: 0
Accepted
time: 51ms
memory: 12932kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
200
1000 611 992 5736784
504 611 954658
504 936 219278
502 936 632439
393 502 177662
267 393 570266
267 291 941365
291 310 168052
310 765 253098
635 765 724932
274 635 842125
274 799 848645
39 799 433118
39 940 705598
553 940 564063
553 960 69665
917 960 6904...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
126
38
69
34
52
33
42
32
39
41
38
36
45
84
40
44
50
42
47
34
38
47
38
37
39
37
44
39
32
33
38
54
25
36
46
33
37
35
28
36
45
43
44
49
37
33
43
44
53
42
33
30
50
41
37
40
37
44
207
31
37
45
36
43
35
40
41
39
135
53
40
32
31
37
34
38
51
48
36
40
48
42
43
43
3...

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #4:

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

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
50 23 25 382806473
0 1 375710
1 2 898637
2 3 10402
3 4 536577
4 5 385023
5 6 71075
6 7 543368
7 8 301497
8 9 174394
9 10 711312
10 11 923006
11 12 675532
12 13 838667
13 14 565729
14 15 979816
15 16 862618
16 17 576015
17 18 177751
18 19 306989
19 20 881492...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
50

result:

wrong answer 1st lines differ - on the 1st token, expected: '96', found: '50'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

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

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 9
0 2 2
1 2 3
2 3 3

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
4

result:

wrong answer 1st lines differ - on the 1st token, expected: '6', found: '4'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%