QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#706664 | #6560. Broken Minimum Spanning Tree | ucup-team902# | WA | 0ms | 3688kb | C++17 | 1.9kb | 2024-11-03 12:51:51 | 2024-11-03 12:51:53 |
Judging History
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;
}
}
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
input:
4 4 1 2 10 2 3 3 3 4 1 1 4 4
output:
1 1 4
result:
ok correct!
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3688kb
input:
6 8 1 2 10 2 3 10 3 4 10 4 5 10 5 6 10 6 1 10 1 3 1 4 6 1
output:
2 2 7 5 6
result:
FAIL participant's MST is better than jury!