제출 #1094242

#제출 시각아이디문제언어결과실행 시간메모리
1094242SunbaeRailway (BOI17_railway)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define z exit(0) using namespace std; const int N = 1e5 + 5, M = 2e5 + 5; vector<int> g[N], vt_g[N]; pair<int,int> Edge[N]; int tin[N], tout[N], idx[N], d[N], V[M], E[M], st[M], T[M], ST[M][20], m, mm, sz; bool anc(int u, int v){ return tin[u] <= tin[v] && tout[v] <= tout[u];} void dfs(int u){ E[m++] = u; for(int v: g[u]){ g[v].erase(find(g[v].begin(), g[v].end(), u)); dfs(v); E[m++] = u; } } bool cmp(int u, int v){ return tin[u] < tin[v];} void efs(int u){ for(int v: vt_g[u]){ ++d[v]; --d[u]; efs(v); } } void ffs(int u){ for(int v: g[u]){ ffs(v); d[u] += d[v]; } } int lca(int u, int v){ if(tin[u] > tin[v]) swap(u, v); int j = 31 - __builtin_clz(tin[v] - tin[u] + 1); return T[min(ST[tin[u]][j], ST[tin[v]-(1<<j)+1][j])]; } signed main(){ int n, q, k; scanf("%d %d %d", &n, &q, &k); for(int i = 0, u, v; i<n-1; ++i){ scanf("%d %d", &u, &v); --u; --v; g[u].push_back(v); g[v].push_back(u); Edge[i] = {u, v}; } dfs(0); for(int i = m-1; i>=0; --i) tin[E[i]] = i, T[i] = E[i]; for(int i = 0; i<m; ++i) ST[i][0] = tin[E[i]], tout[E[i]] = i; for(int j = 1; j<32 - __builtin_clz(m); ++j) for(int i = 0; i+(1<<j)-1<m; ++i) ST[i][j] = min(ST[i][j-1], ST[i+(1<<(j-1))][j-1]); for(int i = 0; i<n-1; ++i){ int u = Edge[i].first, v = Edge[i].second; if(tin[u] > tin[v]) swap(u, v); idx[v] = i; } for(int j = 0; j<q; ++j){ scanf("%d", &m); mm = m; for(int i = 0; i<m; ++i) scanf("%d", V+i), --V[i]; sort(V, V+m, cmp); for(int i = 1; i<m; ++i) V[mm++] = lca(V[i], V[i-1]); m = mm; sort(V, V+m, cmp); m = unique(V, V+m) - V; sz = 0; st[sz++] = V[0]; for(int i = 1; i<m; ++i){ for(; sz > 1 && !anc(st[sz-1], V[i]); --sz) vt_g[st[sz-2]].push_back(st[sz-1]); st[sz++] = V[i]; } for(; sz > 1; --sz) vt_g[st[sz-2]].push_back(st[sz-1]); efs(V[0]); for(int i = 0; i<m; ++i) vt_g[V[i]].clear(); } ffs(0); sz = 0; for(int i = 0; i<n; ++i) if(d[i] >= k) V[sz++] = idx[i]; sort(V, V+sz); printf("%d\n", sz); for(int i = 0; i<sz; ++i) printf("%d ", V[i] + 1); }

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

railway.cpp:22:6: error: ambiguating new declaration of 'void ffs(int)'
   22 | void ffs(int u){
      |      ^~~
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from railway.cpp:1:
/usr/include/strings.h:104:12: note: old declaration 'int ffs(int)'
  104 | extern int ffs (int __i) __THROW __attribute_const__;
      |            ^~~
railway.cpp: In function 'void ffs(int)':
railway.cpp:24:6: warning: statement has no effect [-Wunused-value]
   24 |   ffs(v); d[u] += d[v];
      |   ~~~^~~
railway.cpp: In function 'int main()':
railway.cpp:64:5: warning: statement has no effect [-Wunused-value]
   64 |  ffs(0);
      |  ~~~^~~
railway.cpp:33:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  int n, q, k; scanf("%d %d %d", &n, &q, &k);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%d %d", &u, &v); --u; --v;
      |   ~~~~~^~~~~~~~~~~~~~~~~
railway.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d", &m); mm = m;
      |   ~~~~~^~~~~~~~~~
railway.cpp:50:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   for(int i = 0; i<m; ++i) scanf("%d", V+i), --V[i];
      |                            ~~~~~^~~~~~~~~~~