QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359463#410. TelegraphKrzychXyz0 1ms3612kbC++141.9kb2024-03-20 18:05:312024-03-20 18:05:33

Judging History

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

  • [2024-03-20 18:05:33]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3612kb
  • [2024-03-20 18:05:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxN = 100002;
const long long inf = 9223372036854775800;
int N;
int kier[maxN];
long long ceny[maxN];
int wchd[maxN];
int wchdMin = 0;
set<int> cyklsofar;
long long koszt;
/*void debug() {
    cout << wchdMin << " " << cyklsofar.size() << "\n";
    for(auto kv : cyklsofar) cout << kv << " ";
    cout << "\n";
}*/
void input() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> kier[i] >> ceny[i];
    }
    ceny[0] = inf;
}
void findinitial() {
    int curr = 1;
    while(1) {
        cyklsofar.insert(curr);
        curr = kier[curr];
        if(cyklsofar.count(curr)) {
            cyklsofar.clear();
            break;
        }
    }
    cyklsofar.insert(curr);
    int revval = 0;
    while(1) {
        revval = curr;
        curr = kier[curr];
        wchd[curr] = revval;
        if(ceny[revval] < ceny[wchdMin]) wchdMin = revval;
        if(cyklsofar.count(curr)) {
            break;
        }
        cyklsofar.insert(curr);
    }
    //debug();
}
void addtocycle(int X) {
    long long kosztA = inf;
    long long kosztB = ceny[X] + ceny[wchdMin];
    if(cyklsofar.count(kier[X])) {
        kosztA = ceny[wchd[kier[X]]];
    }
    if(kosztA > kosztB) {
        wchd[X] = wchdMin;
        wchd[kier[wchdMin]] = X;
        kier[X] = kier[wchdMin];
        kier[wchdMin] = X;
        ceny[X] = 0;
        ceny[wchdMin] = 0;
        koszt+= kosztB;
    }
    else {
        ceny[wchd[kier[X]]] = 0;
        kier[wchd[kier[X]]] = X;
        wchd[X] = wchd[kier[X]];
        wchd[kier[X]] = X;
        koszt+=kosztA;
    }
    cyklsofar.insert(X);
}
signed main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    input();
    findinitial();
    for(int i = 1; i <= N; i++) {
        if(!cyklsofar.count(i)) {
            addtocycle(i);
        }
    }
    cout << koszt << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

10
3 85377744
3 191391530
4 553475509
8 344887257
9 812158120
1 880268352
4 686078706
7 182546394
4 220137367
3 89957933

output:

2045086664

result:

wrong answer 1st lines differ - expected: '1081551750', found: '2045086664'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%