Submission #932992

# Submission time Handle Problem Language Result Execution time Memory
932992 2024-02-24T17:36:38 Z ArashJafariyan Network (BOI15_net) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) 0
#endif

typedef long long ll;

int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);

    int n;
    std::cin >> n;

    std::vector<std::vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int v, u;
        std::cin >> v >> u;
        v--; u--;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }

    std::vector<int> leaf;
    auto dfs = [&](auto self, int v, int p) -> void {
        if (adj[v].size() == 1) {
            leaf.push_back(v);
        }
        for (int u : adj[v]) {
            if (u != p) {
                self(self, u, v);
            }
        }
    };
    dfs(dfs, 0, 0);

    int sz = leaf.size();
    cout << (sz + 1) / 2 << '\n';
    for (int i = 0; i + sz / 2 < sz; i++) {
        std::cout << leaf[i] + 1 << ' ' << leaf[i + sz / 2] + 1 << '\n';
    }

    return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:41:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   41 |     cout << (sz + 1) / 2 << '\n';
      |     ^~~~
      |     std::cout
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:75,
                 from net.cpp:1:
/usr/include/c++/10/iostream:61:18: note: 'std::cout' declared here
   61 |   extern ostream cout;  /// Linked to standard output
      |                  ^~~~