QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595391 | #2543. Edges, Colors and MST | gambit# | WA | 0ms | 3808kb | C++17 | 1.2kb | 2024-09-28 13:36:32 | 2024-09-28 13:36:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct Node {
int next, color, idx;
bool operator<(const Node a) const {
if(this->color == a.color) return this->idx < a.idx;
return this->color > a.color;
}
};
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int N, M; cin >> N >> M;
vector<vector<Node>> conn(N);
vector<tuple<int, int, int>> v;
for(int i=0;i<M;i++) {
int a, b, c; cin >> a >> b >> c;
if(a>b) swap(a, b);
v.push_back({a-1, b-1, c}); // {a, b, color}
conn[a-1].push_back({b-1, c, i});
conn[b-1].push_back({a-1, c, i});
}
for(int i=0;i<N;i++) sort(conn[i].begin(), conn[i].end());
int res[M] = {0, };
int cur=1;
for(int i=0;i<M;i++) {
if(!res[i]) {
if(get<2>(v[i])==0) {
vector<int> next;
next.push_back(conn[get<0>(v[i])][0].idx);
next.push_back(conn[get<1>(v[i])][0].idx);
sort(next.begin(), next.end());
for(int nn:next) if(!res[nn]) res[nn]=cur++;
}
res[i]=cur++;
}
}
for(int i=0;i<M;i++) cout << res[i] << ' ';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3808kb
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 4 5 7 9 11 12 13 8 10 3 6 14 15
result:
wrong answer 3rd numbers differ - expected: '5', found: '4'