제출 #1338759

#제출 시각아이디문제언어결과실행 시간메모리
1338759nguyendinhtienShops (NOI24_shops)C++17
0 / 100
138 ms30276 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;
vector<pii> adj[N + 5];

int total, min_w, node;
int color[N + 5];

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 <= m; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    for(int i = 1; i <= n; i++)
    {
        if(color[i]) continue;

        min_w = inf;
        for(auto it : adj[i])
            if(it.se < min_w)
            {
                min_w = it.se;
                node = it.fi;
            }

        total = max(total, min_w);
        if(color[node] != 0) color[i] = 3 - color[node];
        else {
            color[i] = 1;
            color[node] = 3 - color[i];
        }
    }

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

    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...