Submission #1338751

#TimeUsernameProblemLanguageResultExecution timeMemory
1338751nguyendinhtienShops (NOI24_shops)C++17
38 / 100
235 ms34192 KiB
#include <bits/stdc++.h>
#define N 500000
#define ll long long
#define MOD 1000000007
#define inf 2000000000
#define llf 1000000000000000000
// #define base 31
#define MASK(i) (1 << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define fi first
#define se second
#define el '\n'

using namespace std;

int n, m;

int total;
int min_w[N + 5], nei[N + 5], color[N + 5];
vector<int> g[N + 5];

struct Edge{
    int u, v, w;
} edges;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen(".INP", "r", stdin);
    // freopen(".OUT", "w", stdout);

    cin >> n >> m;

    for(int i = 1; i <= n; i++)
    {
        min_w[i] = inf;
        color[i] = -1;
    }

    for(int i = 0; i < m; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;

        if(u == v) continue;

        if(w < min_w[u])
        {
            min_w[u] = w;
            nei[u] = v;
        }

        if(w < min_w[v])
        {
            min_w[v] = w;
            nei[v] = u;
        }
    }

    for(int i = 1; i <= n; i++)
        if(min_w[i] != inf) total = max(total, min_w[i]);

    for(int i = 1; i <= n; i++)
        if(nei[i] != 0)
        {
            int u = i;
            int v = nei[i];
            g[u].push_back(v);
            g[v].push_back(u);
        }

    for(int i = 1; i <= n; i++)
        if(color[i] == -1)
        {
            queue<int> q;
            q.push(i);
            color[i] = 0;

            while(q.size())
            {
                int u = q.front(); q.pop();
                for(int v : g[u])
                    if(color[v] == -1)
                    {
                        color[v] = 1 - color[u];
                        q.push(v);
                    }
            }
        }

    cout << total << el;
    for(int i = 1; i <= n; i++)
        cout << (color[i] == 0 ? 'B' : 'D');

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...