umap 重载运算符求条,玄 2 关
查看原帖
umap 重载运算符求条,玄 2 关
833737
Lyw_and_Segment_Tree楼主2024/6/28 22:22
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int maxn = 5e5 + 5;
int n, m, tot = 0, cnt = 0;
long long dis[maxn], vis[maxn];
long long to[maxn], val[maxn], nxt[maxn], h[maxn];
struct node {
    long long v, w;
    friend bool operator < (node a, node b) {
        return a.w > b.w;
    }
} tmp;
struct dot {
	long long a[15];
	friend bool operator == (dot a, dot b) {
		for(int i = 1; i <= n; i++) {
            if(a.a[i] != b.a[i]) {
                return false; 
            }
        }
        return true;
	}
} s;
unordered_map< dot, int > Map;
priority_queue<node> q;
long long dist(dot x, dot y, long long w) {
	long long sum = 0;
	for(int i = 1; i <= n; i++) {
		sum += ((x.a[i] - y.a[i]) * (x.a[i] - y.a[i]));
	}
	return sum * w;
}
void add(long long u, long long v, long  long w) {
    tot++;
    to[tot] = v;
    val[tot] = w;
    nxt[tot] = h[u];
    h[u] = tot;
}
void Dijkstra(int s) {
    for(int i = 1; i <= 2 * m; i++) dis[i] = inf, vis[i] = 0;
    dis[s] = 0;
    tmp.v = s, tmp.w = 0;
    q.push(tmp);
    while(!q.empty()) {
        long long u = q.top().v;
        q.pop();
        if(vis[u]) continue;
        vis[u] = 1;
        for(long long i = h[u]; i; i = nxt[i]) {
            if(dis[to[i]] >  dis[u] + val[i]) {
                dis[to[i]] = dis[u] + val[i];
                tmp.w = dis[to[i]];
                tmp.v = to[i];
                q.push(tmp);
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
    	dot u, v;
		long long w;
    	for(int j = 1; j <= n; j++) {
    		cin >> u.a[j];
		}
		for(int j = 1; j <= n; j++) {
			cin >> v.a[j];
		}
		if(Map[u] == 0) {
			cnt++;
			Map[u] = cnt; 
		}
		if(Map[v] == 0) {
			cnt++;
			Map[v] = cnt;
		}
		cin >> w;
		w = dist(u, v, w);
		add(Map[u], Map[v], w);
	}
    for(int i = 1; i <= n; i++) {
    	cin >> s.a[i];
	}
	if(Map[s] == 0) cnt++, Map[s] = cnt;
    Dijkstra(Map[s]);
    long long ans = 0;
    for(int i = 1; i <= 2 * m; i++) {
        if(dis[i] != inf) {
            ans += dis[i];
        }
    }
    cout << ans << endl;
}

这个代码会报错,错误信息如下:

/tmp/compiler_zp0zzee4/src:25:27: 错误:使用了被删除的函数‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = dot; _Tp = int; _Hash = std::hash<dot>; _Pred = std::equal_to<dot>; _Alloc = std::allocator<std::pair<const dot, int> >]’
   25 | unordered_map< dot, int > Map;
      |                           ^~~
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/unordered_map:47,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:117,
                 from /tmp/compiler_zp0zzee4/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/unordered_map.h:141:7: 附注:‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = dot; _Tp = int; _Hash = std::hash<dot>; _Pred = std::equal_to<dot>; _Alloc = std::allocator<std::pair<const dot, int> >]’ is implicitly deleted because the default definition would be ill-formed:
  141 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/unordered_map.h:141:7: 错误:使用了被删除的函数‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable() [with _Key = dot; _Value = std::pair<const dot, int>; _Alloc = std::allocator<std::pair<const dot, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<dot>; _H1 = std::hash<dot>; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/unordered_map:46,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:117,
                 from /tmp/compiler_zp0zzee4/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable.h:414:7: 附注:‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::_Hashtable() [with _Key = dot; _Value = std::pair<const dot, int>; _Alloc = std::allocator<std::pair<const dot, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<dot>; _H1 = std::hash<dot>; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’ is implicitly deleted because the default definition would be ill-formed:
  414 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable.h:414:7: 错误:使用了被删除的函数‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits>::_Hashtable_base() [with _Key = dot; _Value = std::pair<const dot, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<dot>; _H1 = std::hash<dot>; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable.h:35,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/unordered_map:46,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:117,
                 from /tmp/compiler_zp0zzee4/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1822:5: 附注:‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2, _Hash, _Traits>::_Hashtable_base() [with _Key = dot; _Value = std::pair<const dot, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<dot>; _H1 = std::hash<dot>; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’ is implicitly deleted because the default definition would be ill-formed:
 1822 |     _Hashtable_base() = default;
      |     ^~~~~~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1822:5: 错误:使用了被删除的函数‘std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::_Hash_code_base() [with _Key = dot; _Value = std::pair<const dot, int>; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash<dot>; _H2 = std::__detail::_Mod_range_hashing]’
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1373:7: 附注:‘std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::_Hash_code_base() [with _Key = dot; _Value = std::pair<const dot, int>; _ExtractKey = std::__detail::_Select1st; _H1 = std::hash<dot>; _H2 = std::__detail::_Mod_range_hashing]’ is implicitly deleted because the default definition would be ill-formed:
 1373 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1373:7: 错误:使用了被删除的函数‘std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<dot>]’
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1096:7: 附注:‘std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<dot>]’ is implicitly deleted because the default definition would be ill-formed:
 1096 |       _Hashtable_ebo_helper() = default;
      |       ^~~~~~~~~~~~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1096:7: 错误:使用了被删除的函数‘std::hash<dot>::hash()’
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/basic_string.h:6719,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/string:55,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/locale_classes.h:40,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/ios_base.h:41,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ios:42,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/istream:38,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/sstream:38,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/complex:45,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ccomplex:39,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:54,
                 from /tmp/compiler_zp0zzee4/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/functional_hash.h:101:12: 附注:‘std::hash<dot>::hash()’ is implicitly deleted because the default definition would be ill-formed:
  101 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/functional_hash.h:101:12: 错误:no matching function for call to ‘std::__hash_enum<dot, false>::__hash_enum()’
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/functional_hash.h:82:7: 附注:candidate: ‘std::__hash_enum<_Tp, <匿名> >::__hash_enum(std::__hash_enum<_Tp, <匿名> >&&) [with _Tp = dot; bool <匿名> = false]’
   82 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/functional_hash.h:82:7: 附注: 备选需要 1 实参,但提供了 0 个
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/functional_hash.h:101:12: 错误:‘std::__hash_enum<_Tp, <匿名> >::~__hash_enum() [with _Tp = dot; bool <匿名> = false]’ is private within this context
  101 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/functional_hash.h:83:7: 附注:declared private here
   83 |       ~__hash_enum();
      |       ^
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable.h:35,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/unordered_map:46,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:117,
                 from /tmp/compiler_zp0zzee4/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/hashtable_policy.h:1096:7: 错误:使用了被删除的函数‘std::hash<dot>::~hash()’
 1096 |       _Hashtable_ebo_helper() = default;
      |       ^~~~~~~~~~~~~~~~~~~~~
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/basic_string.h:6719,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/string:55,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/locale_classes.h:40,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/ios_base.h:41,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ios:42,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/istream:38,
                 from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/
...

求条。

2024/6/28 22:22
加载中...