# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
28586 | 볼빨간 승관이 (#68) | Alternative Mart (FXCUP2_mart) | C++11 | 0 ms | 4416 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using std::vector;
using std::pair;
using pii = pair<int, int>;
vector<pii> dist[50010];
vector<pii> G[50010];
bool chk[50010];
struct node {
int d;
int idx;
int from;
bool operator>(const node& p)const {
return d > p.d;
}
};
pii has(const vector<pii>& vec, int a) {
for (auto& b : vec) {
if (b.second == a)return b;
}
return{ -1,-1 };
}
int main() {
int n, m, k, q;
scanf("%d%d%d%d", &n, &m, &k, &q);
std::queue<node> que;
for (int i = 0; i < k; i++) {
int a;
scanf("%d", &a);
que.push({ 0,a,a });
dist[a].push_back({ 0,a });
}
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
G[a].push_back({ b,c });
G[b].push_back({ a,c });
}
while (!que.empty()) {
int idx = que.front().idx;
que.pop();
chk[idx] = false;
for (pii& p : dist[idx]) {
int d = p.first;
int from = p.second;
for (auto next : G[idx]) {
int to = next.first;
int cost = next.second;
bool has = false;
for (pii& a : dist[to]) {
if (a.second == from) {
has = true;
if (a.first > d + cost) {
a.first = d + cost;
if (!chk[to]) {
chk[to] = true;
que.push({ d + cost, to });
}
}
break;
}
}
if (!has) {
dist[to].push_back({ d + cost,from });
if (dist[to].size() > 11) {
auto it = std::max_element(dist[to].begin(), dist[to].end());
if (it->second != from) {
if (!chk[to]) {
chk[to] = true;
que.push({ d + cost, to });
}
}
dist[to].erase(it);
}
else {
if (!chk[to]) {
chk[to] = true;
que.push({ d + cost, to });
}
}
}
}
}
}
while (q--) {
int s, x;
scanf("%d%d", &s, &x);
int arr[10];
for (int i = 0; i < x; i++) {
scanf("%d", &arr[i]);
chk[arr[i]] = true;
}
for (pii& p : dist[s]) {
if (!chk[p.second]) {
printf("%d %d\n", p.second, p.first);
break;
}
}
for (int i = 0; i < x; i++) {
chk[arr[i]] = false;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |