# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28785 | kriii | Alternative Mart (FXCUP2_mart) | C++14 | 4473 ms | 51040 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 <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
struct phase{
int s,x,c;
bool operator <(const phase &t) const{return c > t.c;}
};
priority_queue<phase> Q;
map<int, int> dist[50505];
vector<pair<int, int> > G[50505];
int N,M,K,q;
pair<int, int> mx(map<int, int> &m)
{
pair<int, int> ret;
for (auto &p : m){
ret = max(ret,{p.second,p.first});
}
return ret;
}
int main()
{
scanf ("%d %d %d %d",&N,&M,&K,&q);
for (int i=0;i<K;i++){
int x; scanf ("%d",&x);
dist[x][x] = 0;
Q.push({x,x,0});
}
for (int i=0;i<M;i++){
int x,y,c;
scanf ("%d %d %d",&x,&y,&c);
G[x].push_back({y,c});
G[y].push_back({x,c});
}
while (!Q.empty()){
int s = Q.top().s, x = Q.top().x, c = Q.top().c; Q.pop();
if (!dist[x].count(s) || dist[x][s] != c) continue;
for (auto &p : G[x]){
int y = p.first;
int nc = c + p.second;
if (dist[y].count(s) && dist[y][s] <= nc) continue;
if (dist[y].size() < 12 || mx(dist[y]) > make_pair(nc,s)){
dist[y][s] = nc;
if (dist[y].size() == 12){
auto p = mx(dist[y]);
dist[y].erase(p.second);
}
Q.push({s,y,nc});
}
}
}
while (q--){
int x,n;
set<int> chk;
scanf ("%d %d",&x,&n); while (n--){
int t; scanf ("%d",&t); chk.insert(t);
}
vector<pair<int, int> > u;
for (auto &p : dist[x]){
u.push_back({p.second,p.first});
}
sort(u.begin(),u.end());
for (auto &p : u){
if(!chk.count(p.second)){
printf ("%d %d\n",p.second,p.first);
break;
}
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |