QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#23014 | #2543. Edges, Colors and MST | FudanU1# | WA | 3ms | 7812kb | C++17 | 1.9kb | 2022-03-11 15:32:50 | 2022-04-30 00:39:56 |
Judging History
answer
#include <stdio.h>
#include <algorithm>
using namespace std;
struct node {
int v , i;
node *next;
} pool[410000] , *g[210000];
int top;
int n , m;
int u[210000] , v[210000] , col[210000];
int fa[210000] , faid[210000] , dep[210000];
int c[210000];
int buf[210000] , cnt;
int ans[210000] , index;
void add ( int u , int v , int i ) {
node *tmp = &pool[++top];
tmp -> v = v; tmp -> i = i; tmp -> next = g[u]; g[u] = tmp;
}
void dfs ( int i , int from ) {
for ( node *j = g[i] ; j ; j = j -> next ) if ( j -> v != from ) {
dep[j->v] = dep[i] + 1;
fa[j->v] = i;
faid[j->v] = j -> i;
dfs ( j -> v , i );
}
}
int find ( int x ) {
int i , t;
for ( i = x ; c[i] > 0 ; i = c[i] ) ;
while ( c[x] > 0 ) {
t = c[x];
c[x] = i;
x = t;
}
return i;
}
void get ( int x , int y ) {
int t;
x = find ( x );
y = find ( y );
while ( x != y ) {
if ( dep[x] < dep[y] ) swap ( x , y );
buf[++cnt] = faid[x];
t = x;
x = find ( fa[x] );
c[t] = x;
//printf ( "%d %d %d\n" , x , y , t );
}
}
void work () {
int i , j;
scanf ( "%d%d" , &n , &m );
for ( i = 1 ; i <= m ; i++ ) {
scanf ( "%d%d%d" , &u[i] , &v[i] , &col[i] );
if ( col[i] == 1 ) {
add ( u[i] , v[i] , i );
add ( v[i] , u[i] , i );
}
}
dep[1] = 1;
dfs ( 1 , -1 );
for ( i = 1 ; i <= n ; i++ ) {
c[i] = -1;
}
for ( i = 1 ; i <= m ; i++ ) {
if ( ans[i] == 0 ) {
if ( c[i] == 1 ) {
if ( dep[u[i]] < dep[v[i]] ) swap ( u[i] , v[i] );
c[u[i]] = fa[u[i]];
ans[i] = ++index;
}
else {
cnt = 0;
get ( u[i] , v[i] );
sort ( buf + 1 , buf + 1 + cnt );
for ( j = 1 ; j <= cnt ; j++ ) ans[buf[j]] = ++index;
ans[i] = ++index;
}
}
//for ( j = 1 ; j <= m ; j++ ) printf ( "%d " , ans[j] );
//printf ( "\n" );
}
for ( i = 1 ; i <= m ; i++ ) {
printf ( "%d%c" , ans[i] , i==m?'\n':' ' );
}
}
int main () {
work ();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 7812kb
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: 1ms
memory: 7792kb
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 4 7 8 10 12 14 15 17 11 13 5 9 6 18
result:
wrong answer 1st numbers differ - expected: '1', found: '2'