Submission #1338750

#TimeUsernameProblemLanguageResultExecution timeMemory
1338750daotuankhoiShops (NOI24_shops)C++20
100 / 100
314 ms62052 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }

const int MAXN = 5e5 + 5;
vector<pair<int, int>> g[MAXN];
vector<int> adj[MAXN];
int n, m, nxt[MAXN], col[MAXN];

void dfs(int u, int p) {
    for (int v : adj[u]) {
        if (v != p) {
            col[v] = 3 - col[u];
            dfs(v, u);
        }
    }
}

int main() {
    #define NAME "test"
    if (fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v, w; cin >> u >> v >> w;
        g[u].emplace_back(w, v);
        g[v].emplace_back(w, u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        sort(g[i].begin(), g[i].end());
        nxt[i] = g[i][0].se;
        ckmax(ans, g[i][0].fi);
        if (nxt[nxt[i]] == i) continue;
        adj[i].emplace_back(nxt[i]);
        adj[nxt[i]].emplace_back(i);
    }
    cout << ans << '\n';
    for (int i = 1; i <= n; i++) {
        if (!col[i]) {
            col[i] = 1;
            dfs(i, 0);
        }
        cout << (col[i] == 1 ? 'B' : 'D');
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...