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;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
int const n=1e5+3;
bitset<n> colored;
vpi adj[n];
ll to[n];
pair<int,vector<ll>>cnt[n];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
F0R(i,N)
{
to[i]=-2e18;
cnt[i].fi=0;
cnt[i].se.clear();
}
vi nw;
F0R(i,K)
{
colored[P[i]]=1;
to[P[i]]=0;
nw.pb(P[i]);
}
F0R(i,M)
{
int u=R[i][0];
int v=R[i][1];
adj[u].pb({v,L[i]});
adj[v].pb({u,L[i]});
}
while(!colored[0])
{
trav(e,nw)
{
trav(chi,adj[e])
{
if(colored[chi.fi])continue;
++cnt[chi.fi].fi;
cnt[chi.fi].se.pb(to[e]+(ll)chi.se);
}
}
nw.clear();
int rec = 1e9;
F0R(i,N)
{
if(colored[i])continue;
if(cnt[i].fi>=2)
{
sort(all(cnt[i].se));
if(cnt[i].se[1]<=rec)
{
if(cnt[i].se[1]<rec)
{
nw.clear();
}
rec=cnt[i].se[1];
nw.pb(i);
}
}
}
trav(e,nw)
{
to[e]=rec;
colored[e]=1;
}
}
return (int)to[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |