QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603894#5064. DFS OrderLJY_ljyCompile Error//C++201.1kb2024-10-01 20:44:042024-10-01 20:44:04

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 20:44:04]
  • 评测
  • [2024-10-01 20:44:04]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> 
using namespace std;

const long long MAXN = 1e5 + 10;
 
inline long long read() {
	register long long x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

long long n, depth[MAXN], size[MAXN];
vector<long long> G[MAXN];

void dfs(long long u, long long fa) {
	depth[u] = depth[fa] + 1;
	size[u] = 1;
	for (long long i = 0; i < G[u].size(); i++) {
		long long v = G[u][i];
		if (v == fa) continue;
		dfs(v, u); 
		size[u] += size[v];
	}
}

int main() {
	long long t = read();
	for (long long u = 1; u <= t; u++) {
		n = read();
		for (long long i = 1; i <= n; i++) G[i].clear();
		for (long long i = 1; i < n; i++) {
			long long x = read(), y = read();
			G[x].push_back(y);
			G[y].push_back(x); 
		}
		depth[0] = 0;
		dfs(1, 0);
		for (long long i = 1; i <= n; i++) {
			printf("%lld %lld\n", depth[i], n + 1 - size[i]);
		}
	}
	return 0;
}

Details

answer.code: In function ‘long long int read()’:
answer.code:11:28: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   11 |         register long long x = 0, f = 1;
      |                            ^
answer.code:11:35: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   11 |         register long long x = 0, f = 1;
      |                                   ^
answer.code: In function ‘void dfs(long long int, long long int)’:
answer.code:29:9: error: reference to ‘size’ is ambiguous
   29 |         size[u] = 1;
      |         ^~~~
In file included from /usr/include/c++/13/string:53,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from answer.code:1:
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:24:27: note:                 ‘long long int size [100010]’
   24 | long long n, depth[MAXN], size[MAXN];
      |                           ^~~~
answer.code:34:17: error: reference to ‘size’ is ambiguous
   34 |                 size[u] += size[v];
      |                 ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:24:27: note:                 ‘long long int size [100010]’
   24 | long long n, depth[MAXN], size[MAXN];
      |                           ^~~~
answer.code:34:28: error: reference to ‘size’ is ambiguous
   34 |                 size[u] += size[v];
      |                            ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:24:27: note:                 ‘long long int size [100010]’
   24 | long long n, depth[MAXN], size[MAXN];
      |                           ^~~~
answer.code: In function ‘int main()’:
answer.code:51:65: error: reference to ‘size’ is ambiguous
   51 |                         printf("%lld %lld\n", depth[i], n + 1 - size[i]);
      |                                                                 ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:24:27: note:                 ‘long long int size [100010]’
   24 | long long n, depth[MAXN], size[MAXN];
      |                           ^~~~