QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526056#5663. Tangle: A DAG for storing transactionsqq11123334WA 0ms3612kbC++201.5kb2024-08-21 10:26:562024-08-21 10:26:59

Judging History

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

  • [2024-08-21 10:26:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-08-21 10:26:56]
  • 提交

answer

#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

const int MAX_N = 10010;
vector<int> adj[MAX_N];            // Adjacency list to store the graph
int own_weight[MAX_N];             // Stores the own weight of each transaction
bitset<MAX_N> approved_by[MAX_N];  // Bitset to track approvals
int cumulative_weight[MAX_N];      // Stores the cumulative weight of each transaction

int main() {
    int n, threshold;
    cin >> n >> threshold;

    for (int i = 2; i <= n + 1; ++i) {
        int x, y, z, wx;
        cin >> x >> y >> z >> wx;
        own_weight[i] = wx;
        adj[y].push_back(i);
        adj[z].push_back(i);
    }

    // Calculate approvals for each transaction
    for (int i = 1; i <= n + 1; ++i) {
        approved_by[i][i] = 1;
        for (int v : adj[i]) {
            approved_by[v] |= approved_by[i];
        }
    }

    int confirmed_count = 0;

    // Calculate cumulative weights and output confirmed transactions
    for (int i = 2; i <= n + 1; ++i) {
        cumulative_weight[i] = own_weight[i];
        for (int j = approved_by[i]._Find_first(); j < MAX_N; j = approved_by[i]._Find_next(j)) {
            if (j != i) {
                cumulative_weight[i] += own_weight[j];
            }
        }

        if (cumulative_weight[i] >= threshold) {
            cout << i << " " << cumulative_weight[i] << endl;
            confirmed_count++;
        }
    }

    cout << confirmed_count << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

6 12
2 0 1 3
3 0 2 2
4 1 2 1
5 2 3 3
6 3 4 4
7 3 5 5

output:

7 13
1

result:

wrong answer 1st lines differ - expected: '2 18', found: '7 13'