552021-01-09 15:48:15mraronÜzletlánccpp11Futási hiba 20/402ms2152 KiB

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

int n,m,a,b;
vector<int> adj[1001];
vector<int> bfs(int x) {
	vector<int> dst(n+1, 1e9);
	queue<int> q;
	q.push(x);
	dst[x]=0;
	while(!q.empty()) {
		int fr=q.front();q.pop();
		for(auto i:adj[fr]) if(dst[i]==1e9) {
			q.push(i);
			dst[i]=dst[fr]+1;
		}
	}
	return dst;
}

int dp[1001][501];
int par[1001][501];
int main() {
	IO;

	cin>>n>>m>>a>>b;
	for(int i=0;i<m;++i) {
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	
	vector<int> A=bfs(a), B=bfs(b);
	vector<pair<int,int>> vals;
	for(int i=1;i<=n;++i) {
		vals.push_back({B[i]-A[i], i}); //by default it's A
	}
	sort(all(vals));
	string res(n,'A');
	ll ans=accumulate(A.begin()+1,A.end(),0);
	for(int i=0;i<n/2;++i) {
		res[vals[i].yy-1]='B';
		ans+=vals[i].xx;
	}
	
	cout<<ans<<"\n"<<res<<"\n";
	
	
	return 0;
}


RészfeladatÖsszpontTesztVerdiktIdőMemória
base20/40
1Elfogadva0/02ms1788 KiB
2Elfogadva0/01ms1828 KiB
3Elfogadva2/21ms1880 KiB
4Elfogadva2/21ms1880 KiB
5Elfogadva3/31ms1884 KiB
6Elfogadva3/31ms1940 KiB
7Elfogadva2/21ms1952 KiB
8Elfogadva2/21ms1908 KiB
9Elfogadva3/31ms1912 KiB
10Elfogadva3/31ms1912 KiB
11Futási hiba0/21ms1964 KiB
12Futási hiba0/21ms1988 KiB
13Futási hiba0/31ms2008 KiB
14Futási hiba0/31ms2024 KiB
15Futási hiba0/21ms2104 KiB
16Futási hiba0/21ms2072 KiB
17Futási hiba0/31ms2144 KiB
18Futási hiba0/31ms2152 KiB