Submission #335749

#TimeUsernameProblemLanguageResultExecution timeMemory
335749ec1117Factories (JOI14_factories)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pi; typedef vector<int> vi; typedef vector<pi> vpi; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define bk back() #define pb push_back #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define For(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define Rof(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define nl '\n' const int MOD = 1e9+7; const ll INF = 1e18; const int MX = 3e5+5; const ld PI = acos((ld)-1); mt19937 rng; // or mt19937_64 template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL // compile with -DLOCAL #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template<int SZ> struct Centroid{ vpi adj[SZ]; int lev[SZ], sub[SZ], par[SZ]; ll dist[32][SZ], stor[SZ], anc[32][SZ];//todo anc bool done[SZ]; vpi cur; void ae(int a, int b, int c){ adj[a].pb(mp(b,c)); adj[b].pb(mp(a,c)); } void dfs(int x, int p){ sub[x]=1; // int mx=0; trav(y,adj[x])if(y.f!=p && !done[y.f]){ par[y.f]=x; dbg(x,y.f); dfs(y.f,x); sub[x]+=sub[y.f]; // mx=max(mx,sub[y.f]); } // cur.pb(mp(mx,x)); } int getCen(int x){ // cur.clear(); // dfs(x,x); // trav(y,cur){ // dbg(x,y.f,y.s); // if(max(y.f,sub[x]-y.f)*2<=sub[x]) // return y.s; // } // assert(false); dfs(x,x); int sz = sub[x]; while (1) { pi mx = {0,0}; for (pi i: adj[x]) if (!done[i.f] && i.f != par[x]) mx = max(mx,{sub[i.f],i.f}); if (mx.f*2 > sz) x = mx.s; else return x; } } void genDist(int n, int par,int lev, ll d, int dad){ dist[lev][n]=d; anc[lev][n]=dad; trav(x,adj[n])if(x.f!=par){ genDist(x.f,n,lev,d+x.s,dad); } } void gen(int CEN, int x){//CEN is prev cen x=getCen(x);done[x]=1; dbg(x); lev[x]=(CEN==-1?0:lev[CEN]+1); genDist(x,x,lev[x],0,x); trav(y,adj[x])if(!done[y.f])gen(x,y.f); } void init(int N){ For(i,N)done[i]=false; For(i,N)stor[i]=INF; gen(-1,0); } void upd(int n, int t=1){ For(i,lev[n]){ if(t==1)ckmin(stor[anc[i][n]],dist[i][n]); else stor[anc[i][n]]=INF; } } ll query(int n){ ll mn=INF; For(i,lev[n]){ ckmin(mn, dist[i][n]+stor[anc[i][n]]); } return mn; } }; Centroid<MX> C; void Init(int N, int A[], int B[], int D[]){ For(i,N-1){ C.ae(A[i],B[i],D[i]); } C.init(N); } ll query(int S, int X[], int T, int Y[]){ ll mn=INF; For(i,S)C.upd(X[i]); For(i,T)ckmin(mn,C.query(Y[i])); For(i,S)C.upd(X[i],-1); } int main(){ int n,q;cin>> n>>q; int a[n],b[n],d[n]; For(i,n-1){ cin>>a[i]; cin>>b[i]; cin>>d[i]; } dbg("HI"); Init(n,a,b,d); }

Compilation message (stderr)

factories.cpp: In function 'll query(int, int*, int, int*)':
factories.cpp:137:1: warning: no return statement in function returning non-void [-Wreturn-type]
  137 | }
      | ^
factories.cpp: In function 'int main()':
factories.cpp:43:18: warning: statement has no effect [-Wunused-value]
   43 | #define dbg(...) 0
      |                  ^
factories.cpp:147:2: note: in expansion of macro 'dbg'
  147 |  dbg("HI");
      |  ^~~
factories.cpp: In instantiation of 'void Centroid<SZ>::gen(int, int) [with int SZ = 300005]':
factories.cpp:106:3:   required from 'void Centroid<SZ>::init(int) [with int SZ = 300005]'
factories.cpp:129:10:   required from here
factories.cpp:43:18: warning: statement has no effect [-Wunused-value]
   43 | #define dbg(...) 0
      |                  ^
factories.cpp:96:3: note: in expansion of macro 'dbg'
   96 |   dbg(x);
      |   ^~~
factories.cpp: In instantiation of 'void Centroid<SZ>::dfs(int, int) [with int SZ = 300005]':
factories.cpp:78:3:   required from 'int Centroid<SZ>::getCen(int) [with int SZ = 300005]'
factories.cpp:95:5:   required from 'void Centroid<SZ>::gen(int, int) [with int SZ = 300005]'
factories.cpp:106:3:   required from 'void Centroid<SZ>::init(int) [with int SZ = 300005]'
factories.cpp:129:10:   required from here
factories.cpp:43:18: warning: statement has no effect [-Wunused-value]
   43 | #define dbg(...) 0
      |                  ^
factories.cpp:62:4: note: in expansion of macro 'dbg'
   62 |    dbg(x,y.f);
      |    ^~~
/tmp/cckwsTg5.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc3k9Rby.o:factories.cpp:(.text.startup+0x0): first defined here
/tmp/cckwsTg5.o: In function `main':
grader.cpp:(.text.startup+0x412): undefined reference to `Query(int, int*, int, int*)'
collect2: error: ld returned 1 exit status