QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414291 | #2543. Edges, Colors and MST | Kevin5307 | WA | 2ms | 9668kb | C++23 | 1.7kb | 2024-05-18 20:21:27 | 2024-05-18 20:21:29 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,m;
vector<pii> G[200200];
int u[200200],v[200200],c[200200];
int depth[200200],f[200200],fa[200200],fe[200200];
int ans[200200];
vector<vector<int>> vec;
inline int anc(int x)
{
while(fa[x]!=x) x=fa[x]=fa[fa[x]];
return x;
}
void dfs(int u,int fa)
{
depth[u]=depth[fa]+1;
f[u]=fa;
for(auto pr:G[u])
if(pr.first!=fa)
{
dfs(pr.first,u);
fe[pr.first]=pr.second;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>u[i]>>v[i]>>c[i];
if(c[i])
{
G[u[i]].pb(v[i],i);
G[v[i]].pb(u[i],i);
}
}
for(int i=1;i<=n;i++)
fa[i]=i;
dfs(1,0);
int cur=0,cur2=0;
for(int i=1;i<=m;i++)
if(!c[i])
{
vector<int> ve;
int a=u[i],b=v[i];
a=anc(a);
b=anc(b);
while(a!=b)
{
if(depth[a]<depth[b]) swap(a,b);
ve.pb(fe[a]);
fa[a]=f[a];
a=anc(a);
}
srt(ve);
for(auto x:ve)
ans[x]=++cur;
ans[i]=++cur;
}
for(int i=1;i<=m;i++)
cout<<ans[i]<<" ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9668kb
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: 9668kb
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'