代码
#include <bits/stdc++.h>
using namespace std;
struct s{
int v,w;
};
vector<vector<s> > G(1000005);
bool inq[1000005];
long long d[1000005];
queue<int> q;
void spfa(int s)
{
memset(inq,0,sizeof(inq));
memset(d,0x3f,sizeof(d));
q.push(s);
d[s]=0;
inq[s]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
for(auto e:G[u])
{
int v=e.v,w=e.w;
if(d[u]+w<d[v])
{
d[v]=d[u]+w;
if(!inq[v])
{
q.push(v);
inq[v]=1;
}
}
}
}
}
int main()
{
int n,m,cnt=1;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int a;
cin>>a;
s b;
b.w=-a;
if(n!=1&&m!=1)
{
if(i==1)
{
if(j!=m)
{
b.v=cnt+1;
G[cnt].insert(b);
b.v=cnt+m;
G[cnt].insert(b);
}
else
{
b.v=cnt+m;
G[cnt].insert(b);
}
}
else if(i==n)
{
if(j!=m)
{
b.v=cnt+1;
G[cnt].insert(b);
b.v=cnt-m;
G[cnt].insert(b);
}
else
{
b.v=cnt-m;
G[cnt].insert(b);
}
}
else
{
b.v=cnt+1;
G[cnt].insert(b);
b.v=cnt+m;
G[cnt].insert(b);
b.v=cnt-m;
G[cnt].insert(b);
}
}
else if(n==1&&m!=1)
{
if(j!=m)
{
b.v=cnt+1;
G[cnt].insert(b);
}
}
else if(m==1&&n!=1)
{
if(i==1)
{
b.v=cnt+m;
G[cnt].insert(b);
}
else if(i==n)
{
b.v=cnt-m;
G[cnt].insert(b);
}
else
{
b.v=cnt+m;
G[cnt].insert(b);
b.v=cnt-m;
G[cnt].insert(b);
}
}
cnt++;
}
}
spfa(1);
cout<<-(d[n*m]);
}
报错
/tmp/compiler_t7ik3_l9/src: 在函数‘int main()’中:
/tmp/compiler_t7ik3_l9/src:55:22: 错误:no matching function for call to ‘std::vector<s>::insert(s&)’
55 | G[cnt].insert(b);
| ^
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/vector:72,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/queue:61,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:86,
from /tmp/compiler_t7ik3_l9/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/vector.tcc:130:5: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*; std::vector<_Tp, _Alloc>::value_type = s]’
130 | vector<_Tp, _Alloc>::
| ^~~~~~~~~~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/vector.tcc:130:5: 附注: 备选需要 2 实参,但提供了 1 个
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/vector:67,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/queue:61,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:86,
from /tmp/compiler_t7ik3_l9/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1290:7: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*; std::vector<_Tp, _Alloc>::value_type = s]’
1290 | insert(const_iterator __position, value_type&& __x)
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1290:7: 附注: 备选需要 2 实参,但提供了 1 个
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1307:7: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*]’
1307 | insert(const_iterator __position, initializer_list<value_type> __l)
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1307:7: 附注: 备选需要 2 实参,但提供了 1 个
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1332:7: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = s]’
1332 | insert(const_iterator __position, size_type __n, const value_type& __x)
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1332:7: 附注: 备选需要 3 实参,但提供了 1 个
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1376:2: 附注:candidate: ‘template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <模板形参-2-2> = <模板形参-1-2>; _Tp = s; _Alloc = std::allocator<s>]’
1376 | insert(const_iterator __position, _InputIterator __first,
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1376:2: 附注: template argument deduction/substitution failed:
/tmp/compiler_t7ik3_l9/src:55:22: 附注: 备选需要 3 实参,但提供了 1 个
55 | G[cnt].insert(b);
| ^
/tmp/compiler_t7ik3_l9/src:57:22: 错误:no matching function for call to ‘std::vector<s>::insert(s&)’
57 | G[cnt].insert(b);
| ^
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/vector:72,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/queue:61,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:86,
from /tmp/compiler_t7ik3_l9/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/vector.tcc:130:5: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*; std::vector<_Tp, _Alloc>::value_type = s]’
130 | vector<_Tp, _Alloc>::
| ^~~~~~~~~~~~~~~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/vector.tcc:130:5: 附注: 备选需要 2 实参,但提供了 1 个
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/vector:67,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/queue:61,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:86,
from /tmp/compiler_t7ik3_l9/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1290:7: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*; std::vector<_Tp, _Alloc>::value_type = s]’
1290 | insert(const_iterator __position, value_type&& __x)
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1290:7: 附注: 备选需要 2 实参,但提供了 1 个
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1307:7: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*]’
1307 | insert(const_iterator __position, initializer_list<value_type> __l)
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1307:7: 附注: 备选需要 2 实参,但提供了 1 个
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1332:7: 附注:candidate: ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = s; _Alloc = std::allocator<s>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<s*, std::vector<s> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = s*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const s*, std::vector<s> >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const s*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = s]’
1332 | insert(const_iterator __position, size_type __n, const value_type& __x)
| ^~~~~~
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1332:7: 附注: 备
...