QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#335101 | #837. Giant Penguin | Jryno1 | Compile Error | / | / | C++14 | 2.8kb | 2024-02-22 17:24:41 | 2024-02-22 17:24:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define mkp(x,y) make_pair(x,y)
const int maxn=2e5+10,inf=1e9;
int n,m,k;
vector<int>G[maxn],tr[maxn],ed[maxn];
int siz[maxn],root,vis[maxn],subt[maxn];
int tfa[maxn];//father of generated tree
int find(int x){return tfa[x]==x?x:tfa[x]=find(tfa[x]);}
pii E[maxn];
vector<pii> kdis[maxn];//the dis from u to key nodes(only parents,inclusive)
int mdis[maxn];//the minval from u to a mark node
int dis[maxn];//for shortest path
void gsiz(int x,int fat){
siz[x]=1;
for(auto v:tr[x]){
if(v==fat||vis[v])continue;
gsiz(v,x);
siz[x]+=siz[v];
}
}
void grt(int x,int fat,int tsiz,pii &mn){
int msiz=tsiz-siz[x];
for(auto v:tr[x]){
if(v==fat||vis[v])continue;
grt(v,x,tsiz,mn);
msiz=max(msiz,siz[v]);
}
mn=min(mn,mkp(msiz,x));
}
vector<int>subnod;
int clev,lev[maxn];
void gsubtr(int x,int fat,int id){
subt[x]=id,subnod.push_back(x);
lev[x]=clev;
for(auto v:tr[x]){
if(v==fat||vis[v])continue;
gsubtr(v,x,id);
}
}
int gtree(int x){
//get new root
gsiz(x,0);
pii b=mkp(inf,-1);
grt(x,0,siz[x],b);
int nrt=b.se,nid=0;
//get subtrees
clev++;
subnod.clear();
subnod.push_back(nrt);
for(auto v:tr[nrt]){
if(vis[v])continue;
nid++,gsubtr(v,nrt,nid);
}
vector<int>ky;
ky.push_back(nrt);
for(auto u:subnod){
if(u==nrt)continue;
for(auto v:G[u]){
if(vis[v]||v==nrt||subt[u]==subt[v]||lev[v]!=clev)continue;
ky.push_back(min(u,v));
}
}
//get shortest paths
sort(ky.begin(),ky.end());
ky.erase(unique(ky.begin(),kyend()),ky,end());
if(n==75000)cout<<ky.size()<<" "<<subnod.size()<<"\n";
else{
for(int i=0;i<ky.size();i++){
int u=ky[i];
for(auto v:subnod)dis[v]=1e9;
dis[u]=0;
queue<int>Q;
Q.push(u);
while(!Q.empty()){
int now=Q.front();
Q.pop();
for(auto v:G[now]){
if(vis[v]||dis[v]<=dis[now]+1)continue;
dis[v]=dis[now]+1;
Q.push(v);
}
}
for(auto v:subnod)kdis[v].push_back(mkp(u,dis[v]));
}
}
//split
vis[nrt]=1;
for(auto v:tr[nrt]){
if(vis[v])continue;
ed[nrt].push_back(gtree(v));
}
return nrt;
}
int main(){
cin.tie(0),cout.tie(0),ios::sync_with_stdio(false);
cin>>n>>m>>k;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
G[u].push_back(v),G[v].push_back(u);
E[i]=mkp(u,v);
}
for(int i=1;i<=n;i++)tfa[i]=i,mdis[i]=1e9;
for(int i=1;i<=m;i++){
int u=find(E[i].fi),v=find(E[i].se);
if(u!=v){
tfa[u]=v;
tr[u].push_back(v),tr[v].push_back(u);
}
}
root=gtree(1);
int q;
cin>>q;
while(q--){
int x,y;
cin>>x>>y;
if(x==1){
for(auto s:kdis[y])mdis[s.fi]=min(mdis[s.fi],s.se);
} else {
int ans=1e9;
for(auto s:kdis[y])ans=min(ans,mdis[s.fi]+s.se);
cout<<ans<<"\n";
}
}
return 0;
}
Details
answer.code: In function ‘int gtree(int)’: answer.code:69:36: error: ‘kyend’ was not declared in this scope 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ^~~~~ answer.code:69:51: error: no matching function for call to ‘end()’ 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~ In file included from /usr/include/c++/13/bits/algorithmfwd.h:39, from /usr/include/c++/13/bits/stl_algo.h:59, from /usr/include/c++/13/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/initializer_list:99:5: note: candidate: ‘template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)’ 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ /usr/include/c++/13/initializer_list:99:5: note: template argument deduction/substitution failed: answer.code:69:51: note: candidate expects 1 argument, 0 provided 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~ In file included from /usr/include/c++/13/string:53, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52: /usr/include/c++/13/bits/range_access.h:74:5: note: candidate: ‘template<class _Container> decltype (__cont.end()) std::end(_Container&)’ 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/13/bits/range_access.h:74:5: note: template argument deduction/substitution failed: answer.code:69:51: note: candidate expects 1 argument, 0 provided 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~ /usr/include/c++/13/bits/range_access.h:85:5: note: candidate: ‘template<class _Container> decltype (__cont.end()) std::end(const _Container&)’ 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/13/bits/range_access.h:85:5: note: template argument deduction/substitution failed: answer.code:69:51: note: candidate expects 1 argument, 0 provided 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~ /usr/include/c++/13/bits/range_access.h:106:5: note: candidate: ‘template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])’ 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/13/bits/range_access.h:106:5: note: template argument deduction/substitution failed: answer.code:69:51: note: candidate expects 1 argument, 0 provided 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~ In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:166: /usr/include/c++/13/valarray:1243:5: note: candidate: ‘template<class _Tp> _Tp* std::end(valarray<_Tp>&)’ 1243 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/13/valarray:1243:5: note: template argument deduction/substitution failed: answer.code:69:51: note: candidate expects 1 argument, 0 provided 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~ /usr/include/c++/13/valarray:1259:5: note: candidate: ‘template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)’ 1259 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/13/valarray:1259:5: note: template argument deduction/substitution failed: answer.code:69:51: note: candidate expects 1 argument, 0 provided 69 | ky.erase(unique(ky.begin(),kyend()),ky,end()); | ~~~^~