제출 #110420

#제출 시각아이디문제언어결과실행 시간메모리
110420luciocfUnique Cities (JOI19_ho_t5)C++14
0 / 100
239 ms16428 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+10; int d[2][maxn], qtd[2][maxn]; int ans[maxn]; vector<int> grafo[maxn]; void dfs(int u, int p) { for (auto v: grafo[u]) { if (v == p) continue; dfs(v, u); if (d[0][v]+1 > d[0][u]) d[1][u] = d[0][u], d[0][u] = d[0][v]+1; else if (d[0][v]+1 > d[1][u]) d[1][u] = d[0][v]+1; } for (auto v: grafo[u]) { if (v == p) continue; if (d[0][v]+1 == d[0][u]) qtd[0][u] += qtd[0][v]; if (d[0][v]+1 == d[1][u]) qtd[1][u] += qtd[0][v]; } if (grafo[u].size() == 1 && u != 1) qtd[0][u] = 1; if (d[1][u] == 0) qtd[1][u] = 1; } void rotate(int u, int p) { if (qtd[0][u] == 1) ans[u] = 1; for (auto v: grafo[u]) { if (v == p) continue; int ant[2] = {d[0][u], qtd[0][u]}; if (d[0][v]+1 == d[0][u]) { d[0][u] = d[1][u], qtd[0][u] = qtd[1][u]; if (d[0][v]+1 == d[0][u]) qtd[0][u] -= qtd[0][v]; } qtd[0][v] = qtd[1][v] = 0; if (d[0][u]+1 > d[0][v]) d[1][v] = d[0][v], d[0][v] = d[0][u]+1; else if (d[0][u]+1 > d[1][v]) d[1][v] = d[0][u]+1; for (auto w: grafo[v]) { if (d[0][w]+1 == d[0][v]) qtd[0][v] += qtd[0][w]; if (d[0][w]+1 == d[1][v]) qtd[1][v] += qtd[0][w]; } rotate(v, u); d[0][u] = ant[0], qtd[0][u] = ant[1]; } } int main(void) { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); grafo[u].push_back(v); grafo[v].push_back(u); } for (int i = 1; i <= m; i++) { int fodase; scanf("%d", &fodase); } dfs(1, 0); rotate(1, 0); for (int i = 1; i <= n; i++) printf("%d\n", ans[i]); }

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

joi2019_ho_t5.cpp: In function 'int main()':
joi2019_ho_t5.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &fodase);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...