QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388724 | #3736. Tree Intersection | SSAABBEERR | Compile Error | / | / | C++20 | 1.7kb | 2024-04-13 18:42:15 | 2024-04-13 18:42:15 |
Judging History
This is the latest submission verdict.
- [2024-04-13 18:42:15]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-04-13 18:42:15]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
#define N 100010
struct Edge {
int v, nxt, id;
} edge[N*2];
unordered_map<int, int> num[N];
int n, col[N], sum[N], cnt[N], e[N], head[N], tot;
void Add(int u, int v, int id) {
edge[tot] = (Edge) { v, head[u], id }; head[u] = tot++;
edge[tot] = (Edge) { u, head[v], id }; head[v] = tot++;
}
void DFS(int u, int fa, int id) {
num[u][col[u]] = 1; cnt[u] = num[u][col[u]] < sum[col[u]] ? 1 : 0;
for(int i = head[u]; ~i; i = edge[i].nxt) {
int v = edge[i].v, idd = edge[i].id;
if(v == fa) continue;
DFS(v, u, idd);
if(num[u].size() < num[v].size()) // 启发式合并
swap(num[u], num[v]), swap(cnt[u], cnt[v]);
for(map<int,int>::iterator it = num[v].begin(); it != num[v].end(); it++) {
int key = it->first, cc = it->second;
if(num[u][key] + cc < sum[key] && num[u][key] == 0) cnt[u]++; // 如果之前没被算过,并且是共有的就要加上
if(num[u][key] + cc == sum[key] && num[u][key] > 0) cnt[u]--; // 如果之前被算过,并且是特有的就要减去
num[u][key] += cc;
}
}
if(id) e[id] = cnt[u];
}
int main() {
while(~scanf("%d", &n)) {
memset(sum, 0, sizeof(sum));
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i <= n; i++) scanf("%d", &col[i]), sum[col[i]]++, num[i].clear();
memset(head, -1, sizeof(head)); tot = 0;
for(int i = 1; i < n; i++) {
int u, v; scanf("%d%d", &u, &v);
Add(u, v, i);
}
DFS(1, -1, 0);
for(int i = 1; i < n; i++) printf("%d\n", e[i]);
}
return 0;
}
详细
answer.code: In function ‘void DFS(int, int, int)’: answer.code:23:53: error: conversion from ‘std::unordered_map<int, int>::iterator’ {aka ‘std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator’} to non-scalar type ‘std::map<int, int>::iterator’ {aka ‘std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator’} requested 23 | for(map<int,int>::iterator it = num[v].begin(); it != num[v].end(); it++) { | ~~~~~~~~~~~~^~ answer.code:23:60: error: no match for ‘operator!=’ (operand types are ‘std::map<int, int>::iterator’ {aka ‘std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator’} and ‘std::unordered_map<int, int>::iterator’ {aka ‘std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator’}) 23 | for(map<int,int>::iterator it = num[v].begin(); it != num[v].end(); it++) { | ~~ ^~ ~~~~~~~~~~~~ | | | | | std::unordered_map<int, int>::iterator {aka std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator} | std::map<int, int>::iterator {aka std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator} In file included from /usr/include/c++/13/regex:68, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:181, from answer.code:1: /usr/include/c++/13/bits/regex.h:1274:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)’ (reversed) 1274 | operator==(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/regex.h:1274:5: note: template argument deduction/substitution failed: answer.code:23:74: note: ‘std::unordered_map<int, int>::iterator’ {aka ‘std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator’} is not derived from ‘const std::__cxx11::sub_match<_BiIter>’ 23 | for(map<int,int>::iterator it = num[v].begin(); it != num[v].end(); it++) { | ^ /usr/include/c++/13/bits/regex.h:1441:5: note: candidate: ‘template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)’ (reversed) 1441 | operator==(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/13/bits/regex.h:1441:5: note: template argument deduction/substitution failed: answer.code:23:74: note: ‘std::unordered_map<int, int>::iterator’ {aka ‘std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator’} is not derived from ‘const std::__cxx11::sub_match<_BiIter>’ 23 | for(map<int,int>::iterator it = num[v].begin(); it != num[v].end(); it++) { | ^ /usr/include/c++/13/bits/regex.h:1613:5: note: candidate: ‘template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)’ (rev...