제출 #285229

#제출 시각아이디문제언어결과실행 시간메모리
285229YJU공장들 (JOI14_factories)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #include "factories.h" #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=5e5+5; const ld pi=3.14159265359; const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll depth[N],parent[N],cut[N],sz[N],ms[N],dis[N]; pll anc[N][21]; vector<pll> v[N]; vector<ll> lis; ll distance(ll nda,ll ndb){ ll tmp=0; if(depth[nda]<depth[ndb])swap(nda,ndb); for(int i=19;i>=0;i--){ if(depth[anc[nda][i].X]>=depth[ndb]){ tmp+=anc[nda][i].Y; nda=anc[nda][i].X; } } if(nda==ndb)return tmp; for(int i=19;i>=0;i--){ if(anc[nda][i].X!=anc[ndb][i].X){ tmp+=anc[nda][i].Y+anc[ndb][i].Y; nda=anc[nda][i].X;ndb=anc[ndb][i].X; } } return tmp+anc[nda][0].Y+anc[ndb][0].Y; } void PDFS(ll nd,ll pa,ll cost){ depth[nd]=depth[pa]+1; anc[nd][0]=mp(pa,cost); REP1(i,20)anc[nd][i]=mp(anc[anc[nd][i-1].X][i-1].X,anc[nd][i-1].Y+anc[anc[nd][i-1].X][i-1].Y); for(auto i:v[nd]){ if(i.X==pa)continue; PDFS(i.X,nd,i.Y); } } void DFS(ll id,ll par){ sz[id]=1;ms[id]=0; for(auto i:v[id]){ if(i.X==par||cut[i.X])continue; DFS(i.X,id); sz[id]+=sz[i.X]; } for(auto i:v[id]){ if(i.X==par||cut[i.X])continue; ms[id]=max(ms[id],sz[i.X]); } lis.pb(id); } void buildc(ll nd,ll pa){ lis.clear(); DFS(nd,0); ll cho=lis[0]; for(auto i:lis)if(max(ms[cho],sz[nd]-sz[cho])>max(ms[i],sz[nd]-ms[i]))cho=i; parent[cho]=pa; cut[cho]=1; for(auto i:v[cho]){ if(cut[i.X]||i.X==pa)continue; buildc(i.X,cho); } } void Init(int n,int A[],int B[],int D[]){ REP1(i,n)dis[i]=INF; REP(i,n){ v[B[i]].pb(mp(A[i],D[i])); v[A[i]].pb(mp(B[i],D[i])); } depth[0]=-1; PDFS(1,0,0); buildc(1,0); } ll Query(ll S,ll x[],ll T,ll y[]){ ll ans=INF; REP(i,S){ ll nd=x[i]; while(nd){ dis[nd]=min(dis[nd],distance(nd,x[i])); nd=parent[nd]; } } REP(i,T){ ll nd=y[i]; while(nd){ ans=min(ans,dis[nd]+distance(nd,y[i])); nd=parent[nd]; } } REP(i,S){ ll nd=x[i]; while(nd){ dis[nd]=INF; nd=parent[nd]; } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

/tmp/ccupfmYE.o: In function `main':
grader.cpp:(.text.startup+0x397): undefined reference to `Query(int, int*, int, int*)'
collect2: error: ld returned 1 exit status