ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1210. Kind Spirits

WA#7
Posted by Duzhy Igor 23 Dec 2006 17:47
What's wrong in my program??? Please, help me, I'm very upset...
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{
   // Input data and determine the result
   int N;
   cin >> N;
   vector<int> prev(30);
   fill(prev.begin(), prev.end(), 0);
   int res=1000000000;
   for(int i=0; i<N; ++i)
   {
      int amount;
      cin >> amount;
      vector<int> cur(30);
      fill(cur.begin(), cur.end(), 1000000000);
      for(int j=0; j<amount; ++j)
      {
         int planet;
         while(cin >> planet && planet)
         {
            int cost;
            cin >> cost;
            cur[j]=min(cur[j], prev[planet-1]+cost);
            res=min(res, cur[j]);
         }
      }
      copy(cur.begin(), cur.end(), prev.begin());
      if(i==N-1)
         continue;
      char ch[1];
      while(cin.read(ch, 1) && ch[0]!='*');
   }
   cout << res << endl;
   return 0;
}
Re: WA#7
Posted by elmariachi1414 (TNU) 22 Jan 2007 00:58
Maybe you should not count

res=min(res, cur[j]);

for EVERY level?
Try just to find minimum for N-th level.
Good luck!
Re: WA#7
Posted by Duzhy Igor 25 Jan 2007 11:55
Thanks very mush!!! I've solved it!!! Good luck :)