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 <cstring>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
vector<int> candidate[10005];
vector<pi> graph[10005];
int n, p, m;
int st[105], vel[105];
bool vis[10005];
void solve(){
scanf("%d %d %d",&n,&p,&m);
for (int i=1; i<=n; i++) {
graph[i].clear();
candidate[i].clear();
}
for (int i=1; i<=p; i++) {
scanf("%d %d",&st[i],&vel[i]);
}
for (int i=0; i<m; i++) {
int d, t, s;
scanf("%d %d %d",&d,&t,&s);
for (int j=1; j<t; j++) {
int u;
scanf("%d",&u);
graph[s].push_back(pi(d,u));
graph[u].push_back(pi(d,s));
s = u;
}
}
priority_queue<pi,vector<pi>,greater<pi> > pq;
for (int i=1; i<=p; i++) {
memset(vis,0,sizeof(vis));
pq.push(pi(0,st[i]));
while (!pq.empty()) {
pi t = pq.top();
pq.pop();
if(vis[t.second]) continue;
vis[t.second] = 1;
candidate[t.second].push_back(t.first * vel[i]);
for (auto &j : graph[t.second]){
if(vis[j.second]) continue;
pq.push(pi(j.first + t.first,j.second));
}
}
}
int pos = -1, posv = 1e9;
for (int i=1; i<=n; i++) {
if(candidate[i].size() != p) continue;
int mv = *max_element(candidate[i].begin(),candidate[i].end());
if(posv > mv) {
posv = mv;
pos = i;
}
}
if(pos == -1) posv = -1;
printf("%d",posv);
}
int main(){
int t;
scanf("%d",&t);
for (int i=1; i<=t; i++) {
printf("Case #%d: ",i);
solve();
puts("");
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |