| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1338808 | po_rag526 | Shops (NOI24_shops) | C++20 | 151 ms | 30228 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define X first
#define Y second
const int maxn = 5e5 + 5;
int n, m, ans = 0, vis[maxn];
stack <int> q;
vector <ii> adj[maxn];
void bfs (int start) {
q.push (start);
vis[start] = 1;
while (!q.empty()) {
int u = q.top();
q.pop();
int res = 1e9;
for (auto [v, w] : adj[u]) {
if (vis[v] == 0) {
vis[v] = 3 - vis[u];
res = min (res, w);
q.push (v);
}
}
if (res != 1e9) ans = max (ans, res);
}
}
signed main () {
#define task "code"
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1, u, v, w; i <= m; i++) {
cin >> u >> v >> w;
adj[u].push_back ({v, w});
adj[v].push_back ({u, w});
}
for (int i = 1; i <= n; i++) {
if (vis[i]) continue;
bfs (i);
}
cout << ans << '\n';
for (int i = 1; i <= n; i++) {
if (vis[i] == 1) cout << 'B';
else cout << 'D';
}
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
