QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#30042#2543. Edges, Colors and MSTyzhangWA 2ms8440kbC++172.1kb2022-04-24 12:18:022022-04-28 12:21:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-28 12:21:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8440kb
  • [2022-04-24 12:18:02]
  • 提交

answer

//μ's forever
#include <bits/stdc++.h>
#define N 200005
//#define getchar nc
using namespace std;
inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
    register int x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}
inline void write(register int x)
{
    if(!x)putchar('0');if(x<0)x=-x,putchar('-');
    static int sta[20];register int tot=0;
    while(x)sta[tot++]=x%10,x/=10;
    while(tot)putchar(sta[--tot]+48);
}
struct edge{
    int to,nxt,id;
}e[N<<1];
int head[N],cnt;
void add(int u,int v,int id){
    e[++cnt]=(edge){v,head[u],id}; head[u]=cnt;
}
struct node{
    int u,v,c;
}E[N];
int n,m;
int fa[N],id[N],dep[N];
void dfs(int x,int f){
    for(int i=head[x];i;i=e[i].nxt){
        int v=e[i].to; if(v==f) continue;
        fa[v]=x,dep[v]=dep[x]+1;
        id[v]=e[i].id;
        dfs(v,x);
    }
}
int fa_[N];
int find(int x){
    return x==fa_[x]?x:fa_[x]=find(fa_[x]);
}
vector<int> kk[N];
void cover(int x,int y,int p){
    x=find(x),y=find(y);
    while(x!=y){
        if(dep[x]<dep[y]) swap(x,y);
        kk[p].push_back(id[x]);
        fa_[x]=fa[x];
        x=find(x);
    }
}
priority_queue<int> q;
int p[N];
int main()
{
    n=read(),m=read();
    for(int i=1;i<=m;++i){
        E[i].u=read(),E[i].v=read(),E[i].c=read();
        if(E[i].c==1){
            add(E[i].u,E[i].v,i);
            add(E[i].v,E[i].u,i);
        }
    }
    dfs(1,0);
    for(int i=1;i<=n;++i) fa_[i]=i;
    for(int i=1;i<=m;++i)
        if(E[i].c!=1){
            cover(E[i].u,E[i].v,i);
        }
    int cv=m;
    for(int i=1;i<=m;++i) if(E[i].c!=1) q.push(i);
    while(!q.empty()){
        int u=q.top(); q.pop();
        p[u]=cv; --cv;
        for(int i=0;i<(int)kk[u].size();++i)
            q.push(kk[u][i]);
    }
    for(int i=1;i<=m;++i)
        printf("%d ",p[i]);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8440kb

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: 2ms
memory: 8404kb

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:

2 3 6 7 9 11 13 14 0 10 12 4 8 5 15 

result:

wrong answer 1st numbers differ - expected: '1', found: '2'