# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
574318 | TimDee | Crocodile's Underground City (IOI11_crocodile) | C++14 | 1 ms | 212 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 "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; i++)
#define pb(x) push_back(x);
#define inf INT_MAX
struct node {
int v;
int val;
};
node makenode(int v, int val) {
//cout<<"make node "<<v<<' '<<val<<'\n';
node ret;
ret.v=v;
ret.val=val;
return ret;
}
void bfs(vector<vector<node>>&adj,vector<int>&val) {
queue<node> q;
//val[0]=1;
q.push(makenode(0,0));
while (!q.empty()) {
node c=q.front();
int v=c.v, x=c.val;
//cout<<v<<' '<<x<<'\n';
q.pop();
if (val[v]>x) {
val[v]=x;
forn(i,adj[v].size()) {
q.push(makenode(adj[v][i].v,adj[v][i].val+x));
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
int n=N, m=M;
vector<int> val(n,inf);
vector<vector<node>> adj(n);
forn(i,m) {
int u=R[i][0], v=R[i][1];
//cout<<"! "<<u<<' '<<v<<' '<<L[i]<<'\n';
adj[u].pb(makenode(v,L[i]));
adj[v].pb(makenode(u,L[i]));
}
bfs(adj,val);
//forn(i,n) cout<<val[i]<<' '; cout<<'\n';
int ans=inf;
vector<int> is_p(n,0);
forn(i,K) {
is_p[P[i]]=1;
}
forn(i,n) {
if (is_p[i]) continue;
int cnt=0;
vector<int> mn;
forn(j,adj[i].size()) {
if (is_p[adj[i][j].v]) {
cnt++;
mn.pb(val[i]+adj[i][j].val);
}
}
sort(mn.begin(),mn.end());
if (cnt>=2) ans=min(ans,mn[1]);
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |