# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29051 | cki86201 | Alternative Mart (FXCUP2_mart) | C++11 | 5000 ms | 130272 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;
int n, m, k, q;
vector <int> mart;
vector <pii> E[50050];
set <pii> S[50050];
map <int, int> M[50050];
void solve() {
scanf("%d%d%d%d", &n, &m, &k, &q);
rep(i, k) {
int x; scanf("%d", &x);
mart.pb(x);
}
rep(i, m) {
int x, y, z; scanf("%d%d%d", &x, &y, &z);
E[x].pb(pii(z, y));
E[y].pb(pii(z, x));
}
priority_queue <t3, vector<t3>, greater<t3> > pq;
for(int e : mart) pq.push(t3(0, e, e)), S[e].insert(pii(0, e)), M[e][e] = 0;
int cnt[50050] = {};
while(!pq.empty()) {
t3 t = pq.top(); pq.pop();
int v = get<1>(t), s = get<2>(t);
int L = get<0>(t);
if(M[v][s] != L) continue;
if(cnt[v] > 11) continue;
++cnt[v];
for(pii e : E[v]) {
if(M[e.Se].find(s) == M[e.Se].end()) {
M[e.Se][s] = L + e.Fi;
S[e.Se].insert(pii(L + e.Fi, s));
pq.push(t3(L + e.Fi, e.Se, s));
}
else if(M[e.Se][s] > L + e.Fi) {
S[e.Se].erase(pii(M[e.Se][s], s));
S[e.Se].insert(pii(L + e.Fi, s));
M[e.Se][s] = L + e.Fi;
pq.push(t3(L + e.Fi, e.Se, s));
}
}
}
while(q--) {
int s, r; scanf("%d%d", &s, &r);
set <int> v;
rep(a, r) {
int x; scanf("%d", &x); v.insert(x);
}
for(pii e : S[s]) if(v.find(e.Se) == v.end()) {
printf("%d %d\n", e.Se, e.Fi);
break;
}
}
}
int main(){
int tc = 1; // scanf("%d", &tc);
for(int t=1;t<=tc;t++) {
solve();
}
return 0;
};
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |