제출 #130592

#제출 시각아이디문제언어결과실행 시간메모리
130592abacaba공장들 (JOI14_factories)C++14
0 / 100
6806 ms223256 KiB
#include "factories.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long const ll inf = 2e15; const int MAX_N = 5e5 + 15; const int MAX_Q = 1e6 + 15; const int MAX_SUM_ST = 1e6 + 15; const int MAX_VALUE = 1e9; int n, m, sz[MAX_N]; ll minn[MAX_N]; vector <int> g[MAX_N], d[MAX_N], pCentroid[MAX_N], dCentroid[MAX_N]; vector <int> is; bool deleted[MAX_N]; void build(int v, int p = -1) { sz[v] = 1; for(auto to : g[v]) if(to != p && !deleted[to]) { build(to, v); sz[v] += sz[to]; } } int centroid(int v, int p, int n) { for(auto to : g[v]) if(!deleted[to] && to != p && sz[to] > n / 2) return centroid(to, v, n); return v; } void dfs(int v, int p, int center, ll dist = 0) { pCentroid[v].pb(center); dCentroid[v].pb(dist); for(int i = 0; i < g[v].size(); ++i) { int to = g[v][i]; ll len = d[v][i]; if(!deleted[to] && to != p) dfs(to, v, center, dist + len); } } void process(int center) { deleted[center] = true; build(center, -1); dfs(center, -1, center); for(int to : g[center]) if(!deleted[to]) process(centroid(to, -1, sz[to])); } void Init(int N, int A[], int B[], int D[]) { n = N; for(int i = 0; i < n; ++i) { g[A[i]].pb(B[i]); d[A[i]].pb(D[i]); g[B[i]].pb(A[i]); d[B[i]].pb(D[i]); } build(1); process(centroid(1, -1, sz[1])); } long long Query(int S, int X[], int T, int Y[]) { ll ans = inf; for(int i = 0; i < T; ++i) for(int j = 0; j < pCentroid[Y[i]].size(); ++j) minn[pCentroid[Y[i]][j]] = inf; for(int i = 0; i < S; ++i) for(int j = 0; j < pCentroid[X[i]].size(); ++j) minn[pCentroid[X[i]][j]] = inf; for(int i = 0; i < S; ++i) for(int j = 0; j < pCentroid[X[i]].size(); ++j) { int s = pCentroid[X[i]][j]; ll d = dCentroid[X[i]][j]; minn[s] = min(minn[s], d); } for(int i = 0; i < T; ++i) for(int j = 0; j < pCentroid[Y[i]].size(); ++j) { int s = pCentroid[Y[i]][j]; ll d = dCentroid[Y[i]][j]; ans = min(ans, minn[s] + 1LL * d); } return ans; }

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

factories.cpp: In function 'void dfs(int, int, int, long long int)':
factories.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[v].size(); ++i) {
                 ~~^~~~~~~~~~~~~
factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:72:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < pCentroid[Y[i]].size(); ++j)
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~
factories.cpp:75:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < pCentroid[X[i]].size(); ++j)
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~
factories.cpp:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < pCentroid[X[i]].size(); ++j) {
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~
factories.cpp:84:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < pCentroid[Y[i]].size(); ++j) {
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...