제출 #1335616

#제출 시각아이디문제언어결과실행 시간메모리
1335616hauserlBosses (BOI16_bosses)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {

    int n; scanf("%d",&n);

    vector<vector<int>> adj(n+1, vector<int>());
    vector<int> boss(n+1, -1);

    for (int i = 1; i <= n; i++) {
        int k; scanf("%d", &k);

        for (int j = 0; j < k; j++) {
            int a; scanf("%d", &a);
            adj[a].push_back(i);
        }
    }


    int maxAmount = 0;
    int max = 1;

    int noBoss = -1;

    for (int i = 1; i <= n; i++) {
        if (maxAmount < adj[i].size()) {
            maxAmount = adj[i].size();
            max = i;
        }
        if (adj[i].size() == 0) noBoss = i;
    }

    if (noBoss != -1) max = noBoss;


    deque<pair<int, int>> q;
    vector<bool> vi(n+1, false);
    q.push_front({max, 1});

    ll sum = 0;

    while(!q.empty()) {
        auto c = q.back(); q.pop_back();
        if (vi[c.first]) continue;
        vi[c.first] = true;
        sum += c.second;

        for (const auto& v : adj[c.first]) {
            q.push_front({v, c.second + 1});
        }
    }

    printf("%d", sum);

    return 0;
}

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

bosses.cpp: In function 'int main()':
bosses.cpp:55:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   55 |     printf("%d", sum);
      |             ~^   ~~~
      |              |   |
      |              int long long int
      |             %lld
bosses.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     int n; scanf("%d",&n);
      |            ~~~~~^~~~~~~~~
bosses.cpp:13:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         int k; scanf("%d", &k);
      |                ~~~~~^~~~~~~~~~
bosses.cpp:16:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             int a; scanf("%d", &a);
      |                    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...