#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
//long long fin = 1;
//vector<pair<long long, long long>> a[n];
long long a[n];
for(int i = 0; i < n ;i++){
a[i]=0;
}
a[0]=1;
// a[0].push_back({1,1});
for(int i = 0; i < n; i++){
long long temp;
cin >> temp;
if(temp==0||a[i]==0){
for(int j = 0; j < temp; j++){
int temp3;
cin >> temp3;
}
continue;
}
long long aa=temp, bb=a[i];
while(aa!=0){
bb%=aa;
if(bb==0){
bb=aa;
}
aa%=bb;
}
bb=temp/bb;
for(int j = 0; j < n; j++){
a[j]*=bb;
}
for(int j = 0; j < temp; j++){
int temp3;
cin >> temp3;
a[temp3-1]+=a[i]/temp;
}
}
cout << a[0];
return 0;
}
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 44 45 46 47 48 | #include<bits/stdc++.h> using namespace std; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); long long n; cin >> n; //long long fin = 1; //vector<pair<long long, long long>> a[n]; long long a[n]; for(int i = 0; i < n ;i++){ a[i]=0; } a[0]=1; // a[0].push_back({1,1}); for(int i = 0; i < n; i++){ long long temp; cin >> temp; if(temp==0||a[i]==0){ for(int j = 0; j < temp; j++){ int temp3; cin >> temp3; } continue; } long long aa=temp, bb=a[i]; while(aa!=0){ bb%=aa; if(bb==0){ bb=aa; } aa%=bb; } bb=temp/bb; for(int j = 0; j < n; j++){ a[j]*=bb; } for(int j = 0; j < temp; j++){ int temp3; cin >> temp3; a[temp3-1]+=a[i]/temp; } } cout << a[0]; return 0; } |
English