QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593331#837. Giant PenguinChenJiarun12345Compile Error//C++142.8kb2024-09-27 13:21:032024-09-27 13:21:03

Judging History

你现在查看的是最新测评结果

  • [2024-09-27 13:21:03]
  • 评测
  • [2024-09-27 13:21:03]
  • 提交

answer

/*
*/
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3f
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define Rof(i,l,r) for(int i=(l);i>=(r);i--)
#define bug cout<<"Ln:"<<__LINE__<<' '
bool MS;
const int N=100005;
int n,m,k,q;
vector<int>e[N],E[N];
struct DSU{
	int fa[N];
	void init(int lim){For(i,1,lim) fa[i]=i;}
	int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
}dsu;
bool vis[N];
int rt,sz[N],SZ[N];
void root(int u,int f){
	sz[u]=1,SZ[u]=0;
	for(int v:e[u]){
		if(v==f||vis[v]) continue;
		root(v,u);sz[u]+=sz[v];
		SZ[u]=max(SZ[u],sz[v]);
	}SZ[u]=max(SZ[u],m-sz[u]);
	if(SZ[u]<SZ[rt]) rt=u;
}
vector<int>vec;int tag[N],uid;
void dfs(int u,int f){
	vec.push_back(u);tag[u]=uid;
	for(int v:e[u]){
		if(v==f||vis[v]) continue;
		uid+=(f==0);dfs(v,u);
	}
}
vector<int>poi;
int fa[N],dep[N],cnt[N],res[N][25],dis[25][25][N];
queue<int>Q;
void calc(int u){
	uid=1;vec.clear();dfs(u,0);
	poi.clear();poi.push_back(u);
	for(int i:vec) for(int j:E[i]) if(tag[j]&&tag[i]!=tag[j]) poi.push_back(i),poi.push_back(j);
	sort(poi.begin(),poi.end()),poi.erase(unique(poi.begin(),poi.end()),poi.end());
	cnt[u]=(int)poi.size();
	For(i,0,cnt[u]-1){
		dis[dep[u]][i][poi[i]]=0,Q.push(poi[i]);
		while(!Q.empty()){
			int U=Q.front();Q.pop();
			for(int V:e[U]) if(tag[V]&&dis[dep[u]][i][V]>dis[dep[u]][i][U]+1) dis[dep[u]][i][V]=dis[dep[u]][i][U]+1,Q.push(V);
			for(int V:E[U]) if(tag[V]&&dis[dep[u]][i][V]>dis[dep[u]][i][U]+1) dis[dep[u]][i][V]=dis[dep[u]][i][U]+1,Q.push(V);
		}
	}
	for(int i:vec) tag[i]=0;
}
void dfz(int u){
	calc(u);vis[u]=1;
	for(int v:e[u]){
		if(vis[v]) continue;
		m=sz[v],SZ[rt=0]=inf;
		root(v,0),root(rt,0);
		fa[rt]=u,dep[rt]=dep[u]+1;
		dfz(rt);
	}
}
void modify(int u){
	for(int i=u;i;i=fa[i]){
		For(j,0,cnt[i]-1){
			res[i][j]=min(res[i][j],dis[dep[i]][j][u]);
		}
	}
}
int query(int u){
	int ans=inf;
	for(int i=u;i;i=fa[i]){
		For(j,0,cnt[i]-1){
			ans=min(ans,res[i][j]+dis[dep[i]][j][u]);
		}
	}
	return ans;
}
void MAIN(int TEST){
	cin>>n>>m>>k;
	dsu.init(n);
	For(i,1,m){
		int u,v;cin>>u>>v;
		int fu=dsu.find(u),fv=dsu.find(v);
		if(fu!=fv) e[u].push_back(v),e[v].push_back(u),dsu.fa[fu]=fv;
		else E[u].push_back(v),E[v].push_back(u);
	}
	memset(res,0x3f,sizeof(res));
	memset(dis,0x3f,sizeof(dis));
	m=n,SZ[rt=0]=inf;
	root(1,0),root(rt,0);
	dfz(rt);
	cin>>q;
	while(q--){
		int t,v;
		cin>>t>>v;
		if(t==1) modify(v);
		else cout<<query(v)<<'\n';
	}
}
bool MT;
signed main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cerr<<"Memory: "<<1.0*(&MS-&MT)/1048576<<"MiB\n";
	int test=1;/*cin>>test;*/For(TEST,1,test) MAIN(TEST);
	return 0;
}

Details

answer.code: In function ‘void dfz(int)’:
answer.code:61:34: error: ‘inf’ was not declared in this scope; did you mean ‘ynf’?
   61 |                 m=sz[v],SZ[rt=0]=inf;
      |                                  ^~~
      |                                  ynf
answer.code: In function ‘int query(int)’:
answer.code:75:17: error: ‘inf’ was not declared in this scope; did you mean ‘ynf’?
   75 |         int ans=inf;
      |                 ^~~
      |                 ynf
answer.code: In function ‘void MAIN(int)’:
answer.code:94:22: error: ‘inf’ was not declared in this scope; did you mean ‘ynf’?
   94 |         m=n,SZ[rt=0]=inf;
      |                      ^~~
      |                      ynf