Submission #1338898

#TimeUsernameProblemLanguageResultExecution timeMemory
1338898bncodero_o123Shops (NOI24_shops)C++20
38 / 100
301 ms62032 KiB
#include <bits/stdc++.h>
#define NAME "code"
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
using namespace std;

const int N= 5e5;
int n, m;
vector<pii> adj[N + 2];

int col[N + 2], nxt[N + 2];
vector<int> n_adj[N + 2];

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

void solve() {
    cin >> n >> m;
    for(int u, v, w, i= 0; i < m; ++i) {
        cin >> u >> v >> w;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    int ans= 0;
    for(int u= 1; u <= n; ++u) {
        int v= 0, mn_w= 1e9 + 5;
        for(auto [k, w] : adj[u])
            if(w < mn_w)
                v= k, mn_w= w;
        nxt[u]= v, ans= max(ans, mn_w);
        if(nxt[v] == u) continue;
        n_adj[u].push_back(v);
        n_adj[v].push_back(u);
    }

    cout << ans << '\n';
    for(int i= 1; i <= n; ++i) {
        if(!col[i]) col[i]= 1, dfs(i);
        cout << (col[i] == 1 ? 'B' : 'D');
    }
}

signed main() {
    if(fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T= 1;
    for(int i= 0; i < T; ++i) solve();

    return 0;
}
  

Compilation message (stderr)

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