QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706675#6560. Broken Minimum Spanning Treeucup-team902#Compile Error//C++171.9kb2024-11-03 12:55:222024-11-03 12:55:23

Judging History

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

  • [2024-11-03 12:55:23]
  • 评测
  • [2024-11-03 12:55:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}

cs int N=3005;

struct edge{
	int u,v,w,id;
	friend bool operator <(cs edge &a,cs edge &b){
		return a.w==b.w?(a.id<b.id):a.w<b.w;
	}
}e[N];
vector<edge>upd,pre,other;

int n,m;
int fa[N],ok[N];
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}

bool merge(int u,int v){
	int f1=find(u),f2=find(v);
	if(f1!=f2){
		fa[u]=v;return true;
	}
	return false;
}
int main(){
	#ifdef Stargazer
	freopen("1.in","r",stdin);
	#endif
	n=read(),m=read();
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w=read();
		e[i].u=u,e[i].v=v,e[i].w=w,e[i].id=i;
	}
	sort(e+1,e+m+1);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int f1=find(e[i].u),f2=find(e[i].v);
		if(f1!=f2){
			fa[f1]=f2;
			if(e[i].id<n)
			ok[e[i].id]=1;
		}
	}
	for(int i=1;i<=m;i++)if(e[i].id>=n)other.pb(e[i]);
	for(int i=1;i<=m;i++)if(e[i].id<n){
		if(ok[e[i].id])
		pre.pb(e[i]);
		else
		upd.pb(e[i]);
	}
	cout<<upd.size()<<'\n';
	for(edge tt:upd){
		for(int i=1;i<=n;i++)fa[i]=i;
		for(edge x:pre){
			int f1=find(x.u),f2=find(x.v);
			assert(f1!=f2);
			fa[f1]=f2;
		}
		for(int i=0;i<other.size();i++){
			edge x=other[i];
			int f1=find(x.u),f2=find(x.v);
			if(f1!=f2){
				pre.pb(x);
				cout<<tt.id<<" "<<x.id<<'\n';
				swap(other[i],other.back());
				other.pop_back();
				break;
			}
		}
		sort(other[i].begin(),other[i].end());
	}
}

详细

answer.code: In function ‘int main()’:
answer.code:91:28: error: ‘i’ was not declared in this scope
   91 |                 sort(other[i].begin(),other[i].end());
      |                            ^