// UVa 12376 - As Long as I Learn, I Live
#include <iostream>
#include <string.h>
using namespace std;
const int MAX_N = 1000;
int main() {
int cases;
cin >> cases;
for (int caseNumber = 1; caseNumber <= cases; caseNumber++) {
int n, m, valueOfNode[MAX_N], bestChoiceFrom[MAX_N];
memset(bestChoiceFrom, 0, sizeof(bestChoiceFrom));
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> valueOfNode[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
if (valueOfNode[b] > valueOfNode[bestChoiceFrom[a]])
bestChoiceFrom[a] = b;
}
int currentNode = 0, sumOfVisitedNodes = 0;
while (bestChoiceFrom[currentNode]) {
currentNode = bestChoiceFrom[currentNode];
sumOfVisitedNodes += valueOfNode[currentNode];
}
cout << "Case " << caseNumber << ": " << sumOfVisitedNodes << " " << currentNode << endl;
}
return 0;
}
Monday, February 13, 2017
UVa 12376 - As Long as I Learn, I Live
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment