제출 #966967

#제출 시각아이디문제언어결과실행 시간메모리
966967blackslex수도 (JOI20_capital_city)C++17
1 / 100
3070 ms12568 KiB
#include<bits/stdc++.h>

using namespace std;

int n, k, x, y;

int main() {
    scanf("%d %d", &n, &k);
    vector<int> c(n + 5), st(k + 5);
    vector<vector<int>> v(n + 5, vector<int>());
    for (int i = 1; i < n; i++) scanf("%d %d", &x, &y), v[x].emplace_back(y), v[y].emplace_back(x);
    for (int i = 1; i <= n; i++) scanf("%d", &c[i]), st[--c[i]] = i;
    vector<bool> f(n + 5);
    function<void(int, int, int)> dfs = [&] (int cur, int par, int msk) {
        if (!(msk & (1 << c[cur]))) return; f[cur] = 1;
        for (auto &e: v[cur]) {
            if (par == e) continue;
            dfs(e, cur, msk);
        }
    };
    int ans = 1e9;
    for (int i = 1; i < (1 << k); i++) {
        f.assign(n + 5, 0);
        int cst = 0;
        for (int j = 1; j <= n; j++) if (i & (1 << c[j])) cst = j;
        dfs(cst, 0, i);
        bool ok = 1;
        for (int j = 1; j <= n; j++) {
            if (i & (1 << c[j])) ok &= f[j];
        }
        if (ok) ans = min(ans, __builtin_popcount(i) - 1);
    }
    printf("%d", ans);
}

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

capital_city.cpp: In lambda function:
capital_city.cpp:15:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |         if (!(msk & (1 << c[cur]))) return; f[cur] = 1;
      |         ^~
capital_city.cpp:15:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |         if (!(msk & (1 << c[cur]))) return; f[cur] = 1;
      |                                             ^
capital_city.cpp: In function 'int main()':
capital_city.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
capital_city.cpp:11:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for (int i = 1; i < n; i++) scanf("%d %d", &x, &y), v[x].emplace_back(y), v[y].emplace_back(x);
      |                                 ~~~~~^~~~~~~~~~~~~~~~~
capital_city.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     for (int i = 1; i <= n; i++) scanf("%d", &c[i]), st[--c[i]] = i;
      |                                  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...