32922023-02-24 11:32:24sztomiEgyirányú egyensúlycpp11Wrong answer 10/5016ms5084 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

int n, m;
vector<int> kifok;
vector<int> befok;
vector<pii> elek;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    int a, b;
    kifok.assign(n+1, 0);
    befok.assign(n+1, 0);
    elek.resize(m);
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        kifok[a]++;
        befok[b]++;
        elek[i] = {a, b};
    }

    // nem nezegettem sokaig, hogy jo-e ez a megoldas szval ez csak proba
    // segit-e ha megforditunk egy elet
    vector<bool> fordult(m, false);
    int elozo, most;
    for(int i = 0; i < m; i++){
        a = elek[i].first;
        b = elek[i].second;
        elozo = abs(kifok[a] - befok[a]) + abs(kifok[b] - befok[b]);
        most = abs((kifok[a]-1) - (befok[a]+1)) + abs((kifok[b]+1) - (befok[b]-1));
        if(elozo > most){
            elek[i].first = b;
            elek[i].second = a;
            fordult[i] = true;
            kifok[a]--;
            befok[a]++;
            kifok[b]++;
            befok[b]--;
        }
    }

    int ossz = 0;
    for(int i = 1; i <= n; i++){
        ossz += abs(kifok[i] - befok[i]);
    }
    cout << ossz << "\n";
    for(int i = 0; i < m; i++){
        cout << (fordult[i] ? "<-" : "->") << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1700 KiB
2Wrong answer0/013ms2680 KiB
3Accepted2/23ms2084 KiB
4Accepted2/23ms2300 KiB
5Accepted2/23ms2500 KiB
6Accepted2/23ms2844 KiB
7Wrong answer0/23ms2940 KiB
8Wrong answer0/23ms2896 KiB
9Accepted2/23ms2976 KiB
10Wrong answer0/23ms3172 KiB
11Wrong answer0/23ms3412 KiB
12Wrong answer0/23ms3624 KiB
13Wrong answer0/34ms3952 KiB
14Wrong answer0/37ms4200 KiB
15Wrong answer0/38ms4108 KiB
16Wrong answer0/39ms3880 KiB
17Wrong answer0/36ms4152 KiB
18Wrong answer0/39ms4292 KiB
19Wrong answer0/39ms4344 KiB
20Wrong answer0/313ms4724 KiB
21Wrong answer0/314ms5084 KiB
22Wrong answer0/316ms5056 KiB