Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <vector>
- #include <cstring>
- #include <iostream>
- using namespace std;
- #define mem(x,y) memset(x,y,sizeof(x))
- #define READ(f) freopen(f, "r", stdin)
- /** Main Code **/
- #define Max 500
- #define No_city 100
- #define No_days 200
- bool visited[No_city + 1][No_days + 1];
- bool dp[No_city + 1][No_days + 1];
- vector<int> adj[Max + 10];
- int cities, edge, start, end, days;
- bool tsp (int city, int days) {
- if(days == 0) {
- if (city == end)
- return true;
- else
- return false;
- }
- if (city == end)
- return false;
- if (visited[city][days])
- return visited[city][days];
- visited[city][days] = true;
- bool ans = false;
- for (int i = 0; i < (int) adj[city].size(); i++) {
- //ans = ans || tsp(adj[city][i], days - 1);
- ans = tsp(adj[city][i], days - 1);
- if(ans == true)
- break;
- }
- return dp[city][days] = ans;
- }
- int main() {
- #ifndef ONLINE_JUDGE
- READ("input.txt");
- #endif
- int u, v;
- while(scanf("%d%d", &cities, &edge) != EOF and cities and edge) {
- for (int i = 0; i < edge; i++) {
- scanf("%d %d", &u, &v);
- adj[u].push_back(v);
- adj[v].push_back(u);
- }
- scanf("%d%d%d", &start, &end, &days);
- mem(visited, false);
- if(tsp(start, days)) {
- printf("Yes, Teobaldo can travel.\n");
- } else {
- printf("No, Teobaldo can not travel.\n");
- }
- for (int i = 0; i < cities + 5; i++) {
- adj[i].clear();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment