Here is a possible C++ implementation to solve the problem:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> getStrongVertices(vector<int>& a, vector<int>& b) {
    int n = a.size();
    vector<int> strongVertices;
    
    // Find the maximum value of a[i] - b[i]
    int maxDiff = a[0] - b[0];
    for (int i = 1; i < n; i++) {
        int diff = a[i] - b[i];
        maxDiff = max(maxDiff, diff);
    }
    
    // Find the vertices that have a[i] - b[i] >= maxDiff for all i
    for (int i = 0; i < n; i++) {
        if (a[i] - b[i] >= maxDiff) {
            strongVertices.push_back(i + 1);
        }
    }
    
    return strongVertices;
}

int main() {
    int t;
    cin >> t;
    
    while (t--) {
        int n;
        cin >> n;
        
        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i];
        }
        
        vector<int> strongVertices = getStrongVertices(a, b);
        
        cout << strongVertices.size() << endl;
        for (int i = 0; i < strongVertices.size(); i++) {
            cout << strongVertices[i] << " ";
        }
        cout << endl;
    }
    
    return 0;
}

This implementation uses a function getStrongVertices to compute the strong vertices for a given test case. It iterates through the arrays a and b to find the maximum difference maxDiff between a[i] - b[i]. Then, it iterates again to find the vertices that have a[i] - b[i] >= maxDiff and adds them to the strongVertices vector. Finally, in the main function, the input is read and the getStrongVertices function is called for each test case, and the result is printed

Given two arrays a and b both of length n Elements of both arrays indexed from 1 to n You are constructing a directed graph where edge from u to v u≠v exists if au−av≥bu−bvA vertex V is called strong

原文地址: https://www.cveoy.top/t/topic/iwS7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录