#include <bits/stdc++.h> using namespace std; #define long long long vector<long> *tas; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long n, p, p1; cin >> n; tas = new vector<long> [n]; long wyn = 1; for (int i = 0; i < n; ++i){ cin >> p; tas[i].resize(p+1); tas[i][0] = p; for (int j = 1; j <= p; ++j) cin >> tas[i][j]; } priority_queue<int> kol; kol.push(1); while (!kol.empty()){ p = kol.top(); kol.pop(); if (tas[p-1][0] != 0){ wyn = wyn/__gcd(wyn,tas[p-1][0])*tas[p-1][0]; for (int i = 1; i <= tas[p-1][0]; ++i){ kol.push(tas[p-1][i]); } } } cout << wyn; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <bits/stdc++.h> using namespace std; #define long long long vector<long> *tas; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long n, p, p1; cin >> n; tas = new vector<long> [n]; long wyn = 1; for (int i = 0; i < n; ++i){ cin >> p; tas[i].resize(p+1); tas[i][0] = p; for (int j = 1; j <= p; ++j) cin >> tas[i][j]; } priority_queue<int> kol; kol.push(1); while (!kol.empty()){ p = kol.top(); kol.pop(); if (tas[p-1][0] != 0){ wyn = wyn/__gcd(wyn,tas[p-1][0])*tas[p-1][0]; for (int i = 1; i <= tas[p-1][0]; ++i){ kol.push(tas[p-1][i]); } } } cout << wyn; } |