# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28619 | Official Fan of ACG (#68) | Alternative Mart (FXCUP2_mart) | C++14 | 0 ms | 4696 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<algorithm>
#include<queue>
#include<functional>
#include<set>
#include<iterator>
using namespace std;
const int INF = 0x3fFFffFF;
const int NMAX = 50000, KMAX = 11;
typedef pair<int, int> pii;
typedef pair<pii, int> tri;
set<pii> dp[NMAX + 1];
vector<pii> g[NMAX + 1];
vector<int> S;
int main() {
int N, M, K, Q; scanf("%d%d%d%d", &N, &M, &K, &Q);
for (int i = 0; i < K; i++) {
int x; scanf("%d", &x); S.push_back(x);
}
for (int i = 0; i < M; i++) {
int u, v, w; scanf("%d%d%d", &u, &v, &w);
g[u].push_back({ v,w });
g[v].push_back({ u,w });
}
priority_queue<tri, vector<tri>, greater<tri>> pq;
for (int s : S) {
pq.push(tri(pii(0, s), s));
dp[s].insert(pii(0, s));
}
while (!pq.empty()) {
auto t = pq.top(); pq.pop();
int here = t.second;
int cost = t.first.first, from = t.first.second;
if (dp[here].count({ cost,from })) {
for (auto edge : g[here]) {
int there = edge.first, ncost = edge.second + cost;
pii nstate = { ncost, from };
bool ok = dp[there].size() < KMAX || nstate < (*dp[there].rbegin());
for (const auto& p : dp[there]) if (p.second == from) ok = false;
if (ok) {
dp[there].insert(nstate);
if (dp[there].size() > KMAX) dp[there].erase(prev(dp[there].end()));
pq.push(tri(pii(ncost, from), there));
}
}
}
}
for (int q = 0; q < Q; q++) {
int st, X; scanf("%d%d", &st, &X);
set<int> fails;
for (int i = 0; i < X; i++) {
int f; scanf("%d", &f); fails.insert(f);
}
for (const auto& p : dp[st]) if (!fails.count(p.second)) {
printf("%d %d\n", p.second, p.first); break;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |