19382022-12-12 11:55:49TomaSajtÜzletlánccpp17Elfogadva 40/4041ms10392 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int n;
void calcDist(const vector<vector<int>>& g, vector<int>& dist, int s) {
    queue<int> q;
    q.push(s);
    dist.assign(n + 1, -1);
    dist[s] = 0;
    while (!q.empty()) {
        int curr = q.front(); q.pop();
        for (int nei : g[curr]) {
            if (dist[nei] != -1) continue;
            dist[nei] = dist[curr] + 1;
            q.push(nei);
        }
    }
}
int main() {
    speed;
    int m, a, b;
    cin >> n >> m >> a >> b;
    vector<vector<int>> g(n + 1);
    vector<bool> vis(n + 1);
    while (m--) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> dista, distb;
    calcDist(g, dista, a);
    calcDist(g, distb, b);
    vector<pair<int, int>> indCombo(n);
    for (int i = 1; i <= n; i++) {
        indCombo[i - 1] = { dista[i] - distb[i],i };
    }
    sort(indCombo.begin(), indCombo.end());
    vector<int> isA(n + 1);
    for (int j = 0; j < n; j++) {
        auto [d, i] = indCombo[j];
        isA[i] = j < n / 2;
    }
    int res = 0;
    for (int i = 1; i <= n; i++) res += isA[i] ? dista[i] : distb[i];
    cout << res << '\n';
    for (int i = 1; i <= n; i++) cout << "BA"[isA[i]];
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1824 KiB
2Elfogadva0/02ms2068 KiB
3Elfogadva2/22ms2096 KiB
4Elfogadva2/22ms2324 KiB
5Elfogadva3/32ms2556 KiB
6Elfogadva3/32ms2732 KiB
7Elfogadva2/22ms2932 KiB
8Elfogadva2/22ms3048 KiB
9Elfogadva3/32ms3128 KiB
10Elfogadva3/32ms3120 KiB
11Elfogadva2/24ms4028 KiB
12Elfogadva2/27ms4172 KiB
13Elfogadva3/323ms6168 KiB
14Elfogadva3/34ms4200 KiB
15Elfogadva2/234ms9956 KiB
16Elfogadva2/237ms10156 KiB
17Elfogadva3/325ms9432 KiB
18Elfogadva3/341ms10392 KiB