제출 #233647

#제출 시각아이디문제언어결과실행 시간메모리
233647almogwald공장들 (JOI14_factories)C++14
0 / 100
29 ms768 KiB
#include "factories.h" #include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <set> #define forr(i,a,b,c) for(int i=a;i<b;i+=c) #define fort(i,a,b) forr(i,a,b,1) #define forn(i,n) fort(i,1,n) #define fori(i,n) fort(i,0,n) #define forrb(i,a,b,c) for(int i=b-1;i>=a;i-=c) #define fortb(i,a,b) forrb(i,a,b,1) #define fornb(i,n) fortb(i,1,n) #define forib(i,n) fortb(i,0,n) using namespace std; #define into(x) cin >> x; typedef vector<int> veci; typedef long long lol; typedef pair<lol,lol> point; #define def(x) lol x; into(x) vector<veci> f; #define logn 19 vector<vector<point>> cons; vector<lol> depth; veci dep; void Init(int N, int A[], int B[], int D[]) { cons.resize(N); f.resize(N); depth.resize(N); dep.resize(N); fori(i, N - 1) { cons[A[i]].push_back({ B[i] , D[i]}); cons[B[i]].push_back({ A[i] , D[i] }); } fori(i, N) { f[i].resize(logn); } veci visited(N); veci stk(1); while (!stk.empty()) { int cur = stk.back(); stk.pop_back(); visited[cur] = 1; forn(i, logn) { f[cur][i] = f[f[cur][i - 1]][i - 1]; } fori(i, cons[cur].size()) { if (visited[cons[cur][i].first] == 0) { f[cons[cur][i].first][0] = cur; dep[cons[cur][i].first] = dep[cur] + 1; depth[cons[cur][i].first] = depth[cur] + cons[cur][i].second; stk.push_back(cons[cur][i].first); } } } } int lca(int l, int r) { int k = logn-1; while (dep[l] != dep[r]) { if (dep[l] + (1 << k) <= dep[r]) { r = f[r][k]; } if (dep[r] + (1 << k) <= dep[l]) { l = f[l][k]; } k--; } if (l == r) { return l; } k = logn - 1; while (k>0) { if (f[r][k]!= f[l][k]) { r = f[r][k]; l = f[l][k]; } k--; } return f[l][0]; } long long Query(int S, int X[], int T, int Y[]) { if (S * T * 5 < dep.size()) { lol minmium = 1298719928229189219; fori(i, S) { fori(j, T) { minmium = min(minmium, depth[X[i]] + depth[Y[j]] - 2 * depth[lca(X[i], Y[j])]); } } return minmium; } else { veci visited(f.size()); set<point> stk; veci ender(f.size()); fori(i, S) { stk.insert({ 0,X[i] }); } fori(j, T) { ender[Y[j]] = 1; } while (!stk.empty()) { auto it = stk.begin(); lol dis = it->first; int cur = it->second; stk.erase(it); if (visited[cur]) { continue; } visited[cur] = 1; if (ender[cur]) { return dis; } fori(i, cons[cur].size()) { stk.insert({ cons[cur][i].second+dis,cons[cur][i].first }); } } } }

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

factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:8:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define forr(i,a,b,c) for(int i=a;i<b;i+=c)
                                    ^
factories.cpp:9:21: note: in expansion of macro 'forr'
 #define fort(i,a,b) forr(i,a,b,1)
                     ^~~~
factories.cpp:11:19: note: in expansion of macro 'fort'
 #define fori(i,n) fort(i,0,n)
                   ^~~~
factories.cpp:48:3: note: in expansion of macro 'fori'
   fori(i, cons[cur].size()) {
   ^~~~
factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:83:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (S * T * 5 < dep.size()) {
      ~~~~~~~~~~^~~~~~~~~~~~
factories.cpp:8:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define forr(i,a,b,c) for(int i=a;i<b;i+=c)
                                    ^
factories.cpp:9:21: note: in expansion of macro 'forr'
 #define fort(i,a,b) forr(i,a,b,1)
                     ^~~~
factories.cpp:11:19: note: in expansion of macro 'fort'
 #define fori(i,n) fort(i,0,n)
                   ^~~~
factories.cpp:114:4: note: in expansion of macro 'fori'
    fori(i, cons[cur].size()) {
    ^~~~
factories.cpp:119:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...