QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595480 | #2543. Edges, Colors and MST | gambit# | WA | 0ms | 3556kb | C++17 | 1.4kb | 2024-09-28 13:48:51 | 2024-09-28 13:48:52 |
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;
for(Node nn:conn[get<0>(v[i])]) {
if(nn.color==1) next.push_back(nn.idx);
else break;
}
for(Node nn:conn[get<1>(v[i])]) {
if(nn.color==1) next.push_back(nn.idx);
else break;
}
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: 3556kb
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: 3548kb
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 8 10 12 13 14 6 7 11 3 9 4 15
result:
wrong answer 4th numbers differ - expected: '6', found: '8'