QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335089#837. Giant PenguinJryno1Compile Error//C++142.8kb2024-02-22 17:11:582024-02-22 17:11:59

Judging History

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

  • [2024-02-22 17:11:59]
  • 评测
  • [2024-02-22 17:11:58]
  • 提交

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());
	for(int i=0;i<ky.size();i++){
		if(i&&ky[i-1]==ky[i])continue;
		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);
	if(n==75000){
		cout<<clock()-T<<"\n";
		return 0;
	}
	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 main()’:
answer.code:114:31: error: ‘T’ was not declared in this scope
  114 |                 cout<<clock()-T<<"\n";
      |                               ^