제출 #645410

#제출 시각아이디문제언어결과실행 시간메모리
645410karrigan공장들 (JOI14_factories)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const long long mx=1e15; struct edg{ int v; long long w; }; vector<edg>g[500001]; long long dis[500001]; int dep[500001]; int st[500001][19]; int sub[500001]; int use[500001]; void dfs(int u,int par){ for (auto v:g[u]){ if (v.v==par)continue; dis[v.v]=v.w+dis[u]; dep[v.v]=dep[u]+1; st[v.v][0]=u; dfs(v.v,u); } } int lca(int u,int v){ if (dep[u]<dep[v])swap(u,v); int k=dep[u]-dep[v]; for (int i=18;i>=0;i--){ if (k>>i&1){ u=st[u][i]; } } if (u==v)return u; for (int i=18;i>=0;i--){ if (st[u][i]==0||st[v][i]==0)continue; if (st[u][i]!=st[v][i]){ u=st[u][i]; v=st[v][i]; } } return st[u][0]; } long long cal(int u,int v){ return dis[u]+dis[v]-2*dis[lca(u,v)]; } int dfs2(int u,int par){ sub[u]=1; for (auto v:g[u]){ int lm=v.v; if (use[lm]||lm==par)continue; dfs2(lm,u); sub[u]+=sub[lm]; } return sub[u]; } int centroid(int u,int p,int sz){ for (auto v:g[u]){ if (use[v.v]||v.v==p)continue; if (sub[v.v]*2>sz)return centroid(v.v,u,sz); } return u; } int par[500001]; long long mxx[500001]; int decompose(int u,int p){ int sz=dfs2(u,0); int cen=centroid(u,0,sz); use[cen]=1; if (p!=0){ par[cen]=p; } for (auto v:g[cen]){ if (use[v.v])continue; decompose(v.v,cen); } return cen; } void Init(int N,int A[],int B[],int D[]){ for (int i=1;i<n;i++){ a[i]++; b[i]++; g[a[i]].push_back({b[i],d[i]}); g[b[i]].push_back({a[i],d[i]}); } dfs(1,0); for (int i=1;i<=18;i++){ for (int j=1;j<=n;j++){ st[i][j]=st[st[i][j-1]][j-1]; } } for (int i=1;i<=n;i++){ mxx[u]=1e17; } decompose(1,0); } void update(int u,int pos){ if (pos==0)return; mxx[pos]=min(mxx[u],cal(u,pos)); update(u,par[pos]); } void res(int u,int pos){ if (pos==0)return; mxx[pos]=1e17; res(u,par[pos]); } long long get(int u,int pos){ long long ans=1e17; if (pos==0)return ans; ans=min(ans,cal(u,pos)+mxx[pos]); ans=min(ans,get(u,par[pos])); return ans; } long long Query(int S,int X[],int T,int Y[]){ for (int i=1;i<=t;i++){ update(y[i],y[i]); } long long ans=1e17; for (int i=1;i<=n;i++){ ans=min(ans,get(x[i],x[i])); } for (int i=1;i<=t;i++){ res(y[i],y[i]); } return ans; }

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

factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:77:16: error: 'n' was not declared in this scope
   77 | for (int i=1;i<n;i++){
      |                ^
factories.cpp:78:5: error: 'a' was not declared in this scope
   78 |     a[i]++;
      |     ^
factories.cpp:79:5: error: 'b' was not declared in this scope
   79 |     b[i]++;
      |     ^
factories.cpp:80:29: error: 'd' was not declared in this scope
   80 |     g[a[i]].push_back({b[i],d[i]});
      |                             ^
factories.cpp:85:21: error: 'n' was not declared in this scope
   85 |     for (int j=1;j<=n;j++){
      |                     ^
factories.cpp:89:17: error: 'n' was not declared in this scope
   89 | for (int i=1;i<=n;i++){
      |                 ^
factories.cpp:90:9: error: 'u' was not declared in this scope
   90 |     mxx[u]=1e17;
      |         ^
factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:112:17: error: 't' was not declared in this scope
  112 | for (int i=1;i<=t;i++){
      |                 ^
factories.cpp:113:12: error: 'y' was not declared in this scope
  113 |     update(y[i],y[i]);
      |            ^
factories.cpp:116:17: error: 'n' was not declared in this scope
  116 | for (int i=1;i<=n;i++){
      |                 ^
factories.cpp:117:21: error: 'x' was not declared in this scope
  117 |     ans=min(ans,get(x[i],x[i]));
      |                     ^
factories.cpp:119:17: error: 't' was not declared in this scope
  119 | for (int i=1;i<=t;i++){
      |                 ^
factories.cpp:120:9: error: 'y' was not declared in this scope
  120 |     res(y[i],y[i]);
      |         ^