QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#63879#5015. 树sjc061031Compile Error//C++172.8kb2022-11-23 15:51:592022-11-23 15:52:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-23 15:52:03]
  • 评测
  • [2022-11-23 15:51:59]
  • 提交

answer

#include "tree.h" 
#include <bits/stdc++.h>
using namespace std;

int root,dep[1010],sz[1010],dis[1010][1010];
vector<int> v[1010],u[1010],nw;
vector<pair<int,int> > e;
bool vis[1010];

unsigned seed=chrono::steady_clock::now().time_since_epoch().count();
mt19937 Rand(seed);

inline void predfs(int x,int pr)
{
	sz[x]=0;
	if(vis[x]) sz[x]=1;
	for(int i=0;i<(int)v[x].size();i++) if(v[x][i]!=pr){
		predfs(v[x][i],x);
		sz[x]+=sz[v[x][i]];
	}
}

inline void dfs(int x,int pr)
{
	if(vis[x]){
		nw.push_back(x);return;
	}
	vector<pair<int,int> > vec;
	for(int i=0;i<(int)v[x].size();i++) if(v[x][i]!=pr){
		if(sz[v[x][i]]>0){
			vec.push_back(make_pair(sz[v[x][i]],v[x][i]));
		}
	}
	sort(vec.begin(),vec.end());reverse(vec.begin(),vec.end());
	int sum=0,pos=0;
	for(int i=(int)vec.size()-1;i>=0;i--){
		sum+=vec[i].first;
		if(sum>sz[x]/2){
			pos=i;break;
		}
	}
	for(int i=0;i<=pos;i++) dfs(vec[i].second,x);
}

inline void solve(vector<int> g,vector<int> h)
{
	if((int)g.size()==1){
		for(int i=0;i<(int)h.size();i++){
			v[g[0]].push_back(h[i]);v[h[i]].push_back(g[0]);
			e.push_back(make_pair(g[0],h[i]));
		}
		return;
	}
	if(h.empty()) return;
	for(int i=0;i<(int)g.size();i++) vis[g[i]]=1;
	predfs(root,-1);nw.clear();dfs(root,-1);
	for(int i=0;i<(int)g.size();i++) vis[g[i]]=0;
	vector<pair<int,int> > vec;
	for(int i=0;i<(int)g.size();i++){
		int sum=0;
		for(int j=0;j<(int)nw.size();j++) sum+=dis[g[i]][nw[j]];
		vec.push_back(make_pair(sum,-g[i]));
	}
	for(int i=0;i<(int)h.size();i++){
		int sum=ask(h[i],nw);
		sum-=(int)nw.size();
		vec.push_back(make_pair(sum,h[i]));
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<(int)vec.size();i++){
		int now=i;
		vector<int> xx,yy;
		while(now<(int)vec.size()&&vec[i].first==vec[now].first){
			if(vec[now].second<0) xx.push_back(-vec[now].second);
			else yy.push_back(vec[now].second);
			now++;
		}
		solve(xx,yy);
		i=now-1;
	}
}

inline void solver(int n,int A,int B)
{
	root=Rand()%n+1;
	dep[root]=0;
	int mx=0;
	for(int i=1;i<=n;i++) if(i!=root){
		dep[i]=ask(root,{i});
		u[dep[i]].push_back(i);
		mx=max(mx,dep[i]);
	}
	for(int i=0;i<(int)u[1].size();i++){
		v[root].push_back(u[1][i]);v[u[1][i]].push_back(root);
		e.push_back(make_pair(root,u[1][i]));
	}
	for(int i=2;i<=mx;i++){
		for(int j=0;j<(int)u[i-1].size();j++){
			for(int k=1;k<=n;k++) dis[u[i-1][j]][k]=-1;
			dis[u[i-1][j]][u[i-1][j]]=0;
			queue<int> q;q.push(u[i-1][j]);
			while(!q.empty()){
				int t=q.front();q.pop();
				for(int k=0;k<(int)v[t].size();k++){
					int x=v[t][k];
					if(dis[u[i-1][j]][x]==-1){
						dis[u[i-1][j]][x]=dis[u[i-1][j]][t]+1;
						q.push(x);
					}
				}
			}
		}
		solve(u[i-1],u[i]);
	}
	for(int i=0;i<(int)e.size();i++) answer(e[i].first,e[i].second);
}

詳細信息

implementer.cpp: In function ‘void regduj260135279::init()’:
implementer.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |                 scanf("%d",&n);
      |                 ~~~~~^~~~~~~~~
implementer.cpp:45:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                         scanf("%d%d",&u,&v);
      |                         ~~~~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc6rDxWS.o: in function `main':
implementer.cpp:(.text.startup+0x1c): undefined reference to `solver(int, int, int)'
collect2: error: ld returned 1 exit status