제출 #1338741

#제출 시각아이디문제언어결과실행 시간메모리
1338741nguyendinhtienShops (NOI24_shops)C++17
38 / 100
213 ms34308 KiB
#include <bits/stdc++.h>
#define N
#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;

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;
    vector<int> min_w(n + 1, inf);
    vector<int> nei(n + 1, 0);

    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++)
        total = max(total, min_w[i]);

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

    vector<int> color(n + 1, -1);
    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] ? '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...