70342023-12-28 10:43:37BenedekMartonÜzletlánccpp11Wrong answer 2/4075ms11492 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

struct s
{
    int er;
    int in;
};

bool f(s a, s b)
{
    return a.er<b.er;
}

int main()
{
    int n, m, a, b, x, y;
    cin >> n >> m >> a >> b;
    vector<int> mat[n+1];
    for(int i=1; i<n+1; i++)
    {
        mat[i].push_back(0);
    }
    for(int i=0; i<m; i++)
    {
        cin >> x >> y;
        mat[x].push_back(y);
        mat[y].push_back(x);
        mat[x][0]++;
        mat[y][0]++;
    }
    int hova[n+1];
    queue<int> q;
    q.push(a);
    for(int i=1; i<n+1; i++)
    {
        hova[i]=-1;
    }
    hova[a]=0;
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(int i=1; i<=mat[x][0]; i++)
        {
            if(hova[mat[x][i]]==-1)
            {
                q.push(mat[x][i]);
                hova[mat[x][i]]=hova[x]+1;
            }
        }
    }

    int hovb[n+1];
    q.push(b);
    for(int i=1; i<n+1; i++)
    {
        hovb[i]=-1;
    }
    hovb[b]=0;
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(int i=1; i<=mat[x][0]; i++)
        {
            if(hovb[mat[x][i]]==-1)
            {
                q.push(mat[x][i]);
                hovb[mat[x][i]]=hovb[x]+1;
            }
        }
    }
    s hovk[n+1];
    for(int i=1; i<n+1; i++)
    {
        hovk[i].er=hova[i]-hovb[i];
        hovk[i].in=i;
    }
    sort(hovk+1, hovk+n+1, f);
    char kar[n+1];
    int mink=0;
    for(int i=1; i<=n/2; i++)
    {
        mink=mink+hova[hovk[i].in];
        kar[hovk[i].in-1]='A';
    }
    for(int i=n/2+1; i<=n; i++)
    {
        mink=mink+hovb[hovk[i].in];
        kar[hovk[i].in-1]='B';
    }
    cout << mink << endl << kar;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/40
1Accepted0/03ms1816 KiB
2Wrong answer0/03ms2052 KiB
3Accepted2/23ms2112 KiB
4Wrong answer0/23ms2344 KiB
5Wrong answer0/33ms2524 KiB
6Wrong answer0/33ms2736 KiB
7Wrong answer0/23ms2952 KiB
8Wrong answer0/23ms3172 KiB
9Wrong answer0/33ms3256 KiB
10Wrong answer0/33ms3396 KiB
11Wrong answer0/28ms4248 KiB
12Wrong answer0/210ms4336 KiB
13Wrong answer0/352ms6428 KiB
14Wrong answer0/37ms4444 KiB
15Wrong answer0/257ms10664 KiB
16Wrong answer0/265ms11152 KiB
17Wrong answer0/341ms10272 KiB
18Wrong answer0/375ms11492 KiB