QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#218280#5598. Profitable TripViktorML 1ms3768kbC++141.6kb2023-10-17 22:34:572023-10-17 22:34:57

Judging History

你现在查看的是最新测评结果

  • [2023-10-17 22:34:57]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:3768kb
  • [2023-10-17 22:34:57]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> points[10000];  //graph
int visited_scores[10000];      //Scores of visited points
vector<int> way_scores;         //Summarize scores of all routes
int n,m,w;      //InputVariables

void reset_visited();
void best_effort(int actual_position, int score);

int main() {
    reset_visited();
    //Input
    cin >> n >> m >> w;

    int from, to, cost;
    for (int i = 0; i < m; i++) {
        cin >> from >> to >> cost;
        points[from].push_back({to, cost});
    }

    best_effort(1,0);
    int max_coins = -200;

    int size = way_scores.size();       //sequential search
    for (int i = 0; i < size; i++) {
        if (way_scores[i] > max_coins) { max_coins = way_scores[i]; }
    }

    cout << max_coins << endl; 
    return 0;
}


void best_effort(int actual_position, int score) {
    if (actual_position == n && (points[actual_position].empty() || visited_scores[actual_position] == score)) { way_scores.push_back(score); reset_visited(); }
    else {
        visited_scores[actual_position] = score;
        int new_score;
        int size = points[actual_position].size();
        for (int i = 0; i < size; i++) {
            new_score = score + points[actual_position][i][1] > w ? w : score + points[actual_position][i][1];
            best_effort(points[actual_position][i][0], new_score);
        }
    }
}

void reset_visited() { for (int i = 0; i < 10000; i++) { visited_scores[i] = -200; } } //make the visited scores unvisited



//I guess I need to consider also where did I come from, so I can better determine when to visit cycles and when do not!

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3680kb

input:

2 1 10
1 2 0

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3740kb

input:

4 4 9
1 2 5
1 3 -2
2 4 1
3 4 10

output:

8

result:

ok single line: '8'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3676kb

input:

4 4 7
1 2 5
1 3 -2
2 4 1
3 4 10

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

3 3 5
1 3 -10
3 2 2
2 3 -1

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

2 1 10
1 2 1

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

2 1 10
1 2 -1

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

2 2 10
1 2 1
2 1 -1

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

2 2 10
1 2 -1
2 1 2

output:

9

result:

ok single line: '9'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

2 2 10
1 2 2
2 1 -1

output:

10

result:

ok single line: '10'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

3 2 10
1 2 3
2 3 3

output:

6

result:

ok single line: '6'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

5 5 100
1 2 100
2 3 100
3 4 100
4 5 100
5 1 100

output:

100

result:

ok single line: '100'

Test #12:

score: -100
Memory Limit Exceeded

input:

5 5 100
1 2 -100
2 3 -100
3 4 -100
4 5 -100
5 1 -100

output:


result: