# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74346 | khsoo01 | Alternative Mart (FXCUP2_mart) | C++11 | 546 ms | 143416 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<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int inf = 1e9;
int n, m, k, q, c[50005], vis[50005], ts;
pii d[50005][12];
vector<pii> adj[50005];
priority_queue<pair<pii,int> > pq;
bool upd (int I, pii V) {
for(int i=0;i<11;i++) {
if(d[I][i] < V) {
pii T = d[I][i];
d[I][i] = V;
for(int j=i+1;j<11;j++) {
if(T.Y == V.Y) return true;
swap(d[I][j], T);
}
return true;
}
if(d[I][i].Y == V.Y) return false;
}
return false;
}
int main()
{
scanf("%d%d%d%d",&n,&m,&k,&q);
for(int i=1;i<=n;i++) {
for(int j=0;j<11;j++) d[i][j] = pii(-inf, 1);
}
for(int i=1;i<=k;i++) {
int T;
scanf("%d",&T);
upd(T, pii(0, -T));
pq.push({pii(0, -T), T});
}
for(int i=1;i<=m;i++) {
int A, B, C;
scanf("%d%d%d",&A,&B,&C);
adj[A].push_back({B, C});
adj[B].push_back({A, C});
}
while(!pq.empty()) {
pii V; int I; tie(V, I) = pq.top(); pq.pop();
if(c[I] == 11 || d[I][c[I]] != V) continue;
c[I]++;
for(auto &T : adj[I]) {
int A, B; tie(A, B) = T;
pii X = pii(V.X-B, V.Y);
if(upd(A, X)) pq.push({X, A});
}
}
while(q--) {
int A, M; ts++;
scanf("%d%d",&A,&M);
for(int i=0;i<M;i++) {
int T;
scanf("%d",&T);
vis[T] = ts;
}
for(int i=0;i<11;i++) {
if(vis[-d[A][i].Y] == ts) continue;
printf("%d %d\n",-d[A][i].Y,-d[A][i].X);
break;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |