32912023-02-24 11:31:13sztomiEgyirányú egyensúlycpp11Runtime error 6/508ms4172 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(n+1);
    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
base6/50
1Accepted0/03ms1696 KiB
2Runtime error0/08ms2512 KiB
3Accepted2/23ms2076 KiB
4Runtime error0/23ms2392 KiB
5Accepted2/23ms2368 KiB
6Runtime error0/23ms2600 KiB
7Runtime error0/23ms2812 KiB
8Runtime error0/23ms3056 KiB
9Accepted2/23ms2932 KiB
10Runtime error0/23ms2996 KiB
11Wrong answer0/23ms3024 KiB
12Wrong answer0/23ms3024 KiB
13Runtime error0/34ms3336 KiB
14Wrong answer0/37ms3972 KiB
15Wrong answer0/38ms3840 KiB
16Runtime error0/34ms3420 KiB
17Wrong answer0/34ms3784 KiB
18Runtime error0/34ms3444 KiB
19Runtime error0/34ms3596 KiB
20Runtime error0/36ms4012 KiB
21Runtime error0/38ms4140 KiB
22Runtime error0/37ms4172 KiB