QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553988 | #8591. Shops | YinLin | Compile Error | / | / | C++14 | 1.9kb | 2024-09-09 01:00:21 | 2024-09-09 01:00:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vi;
void dijkstra(const vector<vi> &adj)
{
priority_queue<ii, vector<ii>, greater<>> pq;
vector<int> dist(adj.size(), INT_MAX);
pq.emplace(0, 0);
dist[0] = 0;
vector<int> parent(adj.size(), -1);
while (!pq.empty())
{
auto [d, u] = pq.top();
pq.pop();
if (d > dist[u])
continue;
for (auto [v, w] : adj[u])
{
if (max(dist[u], w) < dist[v])
{
dist[v] = max(dist[u], w);
pq.emplace(dist[v], v);
parent[v] = u;
}
}
}
const int max_cost = *ranges::max_element(dist);
vector<vector<int>> adj2(adj.size());
for(int i= 0; i < adj.size(); i++)
{
int u = i;
if(int v = parent[i]; v != -1)
{
adj2[u].emplace_back(v);
adj2[v].emplace_back(u);
}
}
vector<int> visited(adj.size());
function<void(int, int)> dfs = [&](const int u, const int color)
{
visited[u] = color;
for(const int v : adj2[u])
{
if(!visited[v])
{
dfs(v, (color==1)? 2 : 1);
}
}
};
dfs(0, 1);
cout << max_cost << '\n';
for(int i = 0; i < adj.size(); i++)
{
if(visited[i] == 1)
{
cout << 'D';
}
else
{
cout << 'B';
}
}
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vi> adj(n);
for (int i = 0; i < m; i++)
{
int u, v, w;
cin >> u >> v >> w;
u--, v--;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
dijkstra(adj);
return 0;
}
Details
answer.code: In function ‘void dijkstra(const std::vector<std::vector<std::pair<int, int> > >&)’: answer.code:18:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 18 | auto [d, u] = pq.top(); | ^ answer.code:22:19: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 22 | for (auto [v, w] : adj[u]) | ^ answer.code:32:27: error: ‘ranges’ has not been declared 32 | const int max_cost = *ranges::max_element(dist); | ^~~~~~ answer.code:37:12: warning: init-statement in selection statements only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 37 | if(int v = parent[i]; v != -1) | ^~~