Submission

Status:

[-SSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: gay69

Problemset: เรียงสตริง

Language: cpp

Time: 0.003 second

Submitted On: 2025-09-22 19:13:32

#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

set<string> destroyedCities;
// A set containing the destroyed cities.

map<string,int> cityStrength;
// A map with key as the city name, and the mapped value as the strength of corresponding city.

map<string,vector<string>> adjacentCities;
// A map with key as the city name, and the mapped value as vector of strings which are its adjacent cities.

void burn(string currentCityName,string previousCityName,int firePower){
    if (firePower <= cityStrength[currentCityName]) {
        return;
    }
    destroyedCities.insert(currentCityName);
    for (auto e : adjacentCities[currentCityName]) {
        if (e == previousCityName) {
            continue;
        }
        burn(e, currentCityName, firePower - cityStrength[currentCityName]);
    }
}
int main(){
    int N,S,K,P;
    string C,c,I;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> C >> S >> K;
        cityStrength[C]=S;
        for(int j=0;j<K;j++){
            cin >> c;
            adjacentCities[C].push_back(c);
        }
    }
    cin >> I >> P;
    burn(I,"",P);
    set<string>::iterator it;
    cout << destroyedCities.size() << endl;
    for(it=destroyedCities.begin();it!=destroyedCities.end();it++){
        cout << *it << endl;
    }
}