#include #include using namespace std;

int main() { int N, T; cin >> N >> T; string status; cin >> status; vector<vector> interactions; for (int i = 0; i < T; i++) { int t, x, y; cin >> t >> x >> y; interactions.push_back({t, x, y}); }

int x = 0;
int y = 0;
int z = INT_MAX;

// Iterate through all possible cows as zero patient
for (int i = 0; i < N; i++) {
    vector<int> infected(N, 0);
    infected[i] = 1;
    bool is_infected = true;
    int min_k = INT_MAX;
    int max_k = 0;
    
    // Iterate through all interactions
    for (int j = 0; j < T; j++) {
        int t = interactions[j][0];
        int cow1 = interactions[j][1] - 1;
        int cow2 = interactions[j][2] - 1;
        
        // If both cows are infected, update min_k and max_k
        if (infected[cow1] && infected[cow2]) {
            int k = t - min_k;
            min_k = t;
            max_k = max(max_k, k);
        }
        
        // If only one cow is infected, infect the other cow
        if (infected[cow1] && !infected[cow2]) {
            infected[cow2] = 1;
        }
        
        if (!infected[cow1] && infected[cow2]) {
            infected[cow1] = 1;
        }
    }
    
    // If any healthy cow remains, the zero patient cannot be this cow
    for (int j = 0; j < N; j++) {
        if (!infected[j]) {
            is_infected = false;
            break;
        }
    }
    
    // Update the possible values of x, y, z
    if (is_infected) {
        x++;
        y = max(y, max_k);
        z = min(z, max_k);
    }
}

if (z == INT_MAX) {
    cout << x << ' ' << y << ' ' << "Infinity" << endl;
} else {
    cout << x << ' ' << y << ' ' << z << endl;
}

return 0;

}

COWVID-19 的传播分析:寻找零号病人和传播次数

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

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