QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227159 | #2543. Edges, Colors and MST | JooDdae | WA | 2ms | 9908kb | C++20 | 1.3kb | 2023-10-27 00:03:00 | 2023-10-27 00:03:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, ans[200200], lev[200200], p[200200];
vector<array<int, 2>> v[200200];
array<int, 2> par[200200];
bool chk[200200];
int find(int x) {
if(x == p[x]) return x;
return p[x] = find(p[x]);
}
void dfs(int u, int p) {
lev[u] = lev[p]+1;
for(auto [x, id] : v[u]) if(x != p) {
par[x] = {u, id};
dfs(x, u);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
vector<array<int, 3>> edge;
for(int i=1;i<=m;i++) {
int x, y, c; cin >> x >> y >> c;
if(c) v[x].push_back({y, i}), v[y].push_back({x, i});
else edge.push_back({x, y, i}), chk[i] = 1;
}
dfs(1, 0);
iota(p+1, p+1+n, 1);
int last = 1, cnt = 0;
for(auto [x, y, i] : edge) {
while(last <= i) {
if(!ans[last] && !chk[last]) ans[last] = ++cnt;
last++;
}
x = find(x), y = find(y);
vector<int> l;
while(x != y) {
if(lev[x] < lev[y]) swap(x, y);
l.push_back(par[x][1]), x = p[x] = find(par[x][0]);
}
sort(l.begin(), l.end());
for(auto x : l) if(!ans[x]) ans[x] = ++cnt;
ans[i] = ++cnt;
}
for(int i=1;i<=m;i++) cout << ans[i] << " ";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9688kb
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: 0
Accepted
time: 0ms
memory: 9760kb
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:
1 2 5 6 8 10 12 13 14 9 11 3 7 4 15
result:
ok 15 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 9756kb
input:
8 15 4 7 1 3 6 1 1 5 0 5 7 0 4 5 1 1 2 0 4 8 1 1 3 0 1 4 1 2 4 0 3 8 1 6 8 0 2 5 1 7 8 0 3 5 0
output:
1 2 5 6 3 8 9 11 4 12 10 13 7 14 15
result:
ok 15 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 9756kb
input:
6 13 4 5 0 5 6 0 1 2 0 1 6 0 1 5 0 2 3 0 3 5 0 3 6 0 4 6 1 2 4 1 2 5 1 1 3 1 1 4 1
output:
3 5 7 8 9 11 12 13 4 1 2 10 6
result:
ok 13 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 9780kb
input:
9 22 2 4 1 5 6 1 3 6 0 1 2 1 1 7 0 2 3 0 7 8 0 3 8 0 6 7 0 5 7 1 8 9 0 1 5 1 3 5 1 2 8 0 1 4 0 1 9 1 1 8 0 5 8 1 2 6 0 3 9 0 5 9 0 2 9 0
output:
1 2 4 5 8 9 11 12 13 6 15 7 3 16 17 14 18 10 19 20 21 22
result:
ok 22 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 9776kb
input:
4 6 1 2 1 3 4 0 1 3 1 2 4 0 1 4 1 2 3 0
output:
1 4 2 5 3 6
result:
ok 6 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 9644kb
input:
4 6 1 3 0 2 3 0 1 4 0 2 4 1 3 4 1 1 2 1
output:
4 5 6 1 2 3
result:
ok 6 numbers
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 9908kb
input:
18 20 2 15 1 9 15 1 4 11 1 2 8 0 8 12 1 4 7 1 1 2 0 9 18 1 13 15 1 1 4 1 4 17 1 12 15 1 5 10 0 5 15 1 4 14 1 2 3 1 10 17 1 16 17 1 6 14 1 2 17 1
output:
1 2 3 6 4 7 11 12 13 8 9 5 16 14 0 0 15 0 0 10
result:
wrong answer 15th numbers differ - expected: '17', found: '0'