Finished c and d, e doesn't check for faulty arrangements

This commit is contained in:
2021-12-05 02:35:53 +01:00
parent b94359378b
commit 61b6cbc2c7
3 changed files with 120 additions and 21 deletions

View File

@@ -2,23 +2,58 @@
using namespace std;
void test_case(int tc){
typedef long long ll;
set<int> learnedMoves;
vector<pair<ll, vector<int>>> movelist;
ll result = 0;
void handleMove(int move){
auto s = learnedMoves.size();
learnedMoves.insert(move);
if(s == learnedMoves.size()){
return;
}
result += movelist[move - 1].first;
for(int neededMove : movelist[move - 1].second){
handleMove(neededMove);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
int n;
cin >> n;
for(int tc = 1; tc <= t; ++tc){
test_case(tc);
movelist.reserve(n);
for(int i = 0; i < n; ++i){
ll t;
int k;
cin >> t >> k;
vector<int> neededMoves(k);
for(int j = 0; j < k; ++j){
cin >> neededMoves[j];
}
movelist[i].first = t;
movelist[i].second = neededMoves;
}
result += movelist[n - 1].first;
for(int move : movelist[n - 1].second){
handleMove(move);
}
cout << result;
cout << flush;
return 0;