QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694250 | #2543. Edges, Colors and MST | OOBMABTRAMS# | WA | 4ms | 37208kb | C++14 | 1.2kb | 2024-10-31 17:33:50 | 2024-10-31 17:33:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1e9+7;
const int N=1000013;
int f[N],p[N],idx[N];
int top(int x){return x==f[x]?x:f[x]=top(f[x]);}
void mg(int x,int y) {
x=top(x),y=top(y);
f[top(x)]=top(y);
}
int ans[N],dep[N];
vector<pair<int,int>>mp[N];
void dfs(int x,int fa) {
dep[x]=dep[fa]+1,p[x]=fa;
for(auto[i,id]:mp[x])if(i^fa)idx[i]=id,dfs(i,x);
}
void solve(){
int n;
cin>>n;
int m;
cin>>m;
iota(f,f+n+1,0);
vector<tuple<int,int,int>>zero;
for(int i=1,x,y,z;i<=m;i++) {
cin>>x>>y>>z;
if(z)mp[x].emplace_back(y,i),mp[y].emplace_back(x,i);
else zero.emplace_back(x,y,i);
}
int tot=0;
dfs(1,0);
for(auto[x,y,id]:zero) {
vector<int>col;
while(x!=y){
x=top(x),y=top(y);
if(dep[x]<dep[y])swap(x,y);
if(x==y)break;
col.push_back(idx[x]),mg(x,p[x]),x=top(p[x]);
}
sort(col.begin(),col.end());
for(auto i:col)ans[i]=++tot;
ans[id]=++tot;
}
for(int i=1;i<=m;i++)cout<<ans[i]<<' ';cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
int T=1;
//cin>>T;
while(T--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 37208kb
input:
4 5 1 2 0 2 3 1 3 4 1 2 4 0 1 3 1
output:
3 1 4 5 2
result:
ok 5 number(s): "3 1 4 5 2"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 37084kb
input:
9 15 1 4 1 3 5 1 3 9 0 1 3 0 2 5 0 5 8 0 6 9 0 8 9 0 1 7 1 1 8 1 6 8 1 4 9 1 2 4 1 3 4 1 4 6 0
output:
4 6 3 5 8 10 12 13 0 9 11 1 7 2 14
result:
wrong answer 1st numbers differ - expected: '1', found: '4'