QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#595480#2543. Edges, Colors and MSTgambit#WA 0ms3556kbC++171.4kb2024-09-28 13:48:512024-09-28 13:48:52

Judging History

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

  • [2024-09-28 13:48:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3556kb
  • [2024-09-28 13:48:51]
  • 提交

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'