scanf永远不要使用.在C++中,使用动态容器和iostream:
#include <iostreams>
#include <vector>
int main()
{
unsigned int n;
int q;
if (!(std::cin >> n >> q)) { /* error! */ }
std::vector<Tree> forest(n);
// ...
}
Run Code Online (Sandbox Code Playgroud)
根据您的设置,最好先逐行读取然后处理每一行; 搜索这个网站,因为这已被回答了一百次.