/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int work(int)':
/in/foo.cc:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < E[x].size(); i++) {
                 ~~^~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 7ms 3.105 MiB
#2 Accepted 5ms 3.715 MiB
#3 Accepted 5ms 4.25 MiB
#4 Accepted 4ms 3.09 MiB
#5 Accepted 5ms 3.598 MiB
#6 Accepted 72ms 5.352 MiB
#7 Accepted 93ms 6.617 MiB
#8 Accepted 88ms 6.074 MiB
#9 Accepted 58ms 5.477 MiB
#10 Accepted 77ms 5.703 MiB

代码

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int N = 120000;
vector<int> E[N];
map<vector<int>, int> id;
int ans[N], p[N], vis[N];
int n, cnt;
int work(int x) {
	vector<int> u;
	for(int i = 0; i < E[x].size(); i++) {
		int y = E[x][i];
		u.push_back(work(y));
	}
	sort(u.begin(), u.end());
	if (!id[u]) id[u] = ++cnt;
	ans[x] = id[u];
	return ans[x];
}


int main(){
	scanf("%d", &n);
	for(int i = 2; i <= n; i++){
		scanf("%d", &p[i]);
		E[p[i]].push_back(i);
	}
	work(1);
	cnt = 0;

	for(int i = 1; i <= n; i++) {
		if (!vis[ans[i]]) {
			vis[ans[i]] = ++cnt;
		}
		ans[i] = vis[ans[i]];
	}

	for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
	puts("");
}

信息

递交者
类型
递交
题目
树的同构 T2
题目数据
下载
语言
C++
递交时间
2017-10-06 20:11:13
评测时间
2017-10-06 20:11:13
评测机
分数
100
总耗时
418ms
峰值内存
6.617 MiB