UVA Live archivwe5818 : WA

Do you want to discuss about these problems? Go now!
Users are shared (no need to re-register).

Moderator: Board moderators

Post Reply
starain
New poster
Posts: 4
Joined: Thu Nov 15, 2012 10:49 pm

UVA Live archivwe5818 : WA

Post by starain »

http://uva.onlinejudge.org/external/123/12376.html

Code: Select all

#include <iostream>
#include <cstdio>
#include "vector"
#include "queue"
#include "cstring"
#include "algorithm"

//N, maximum number of node
#define N 100

using namespace std;

int n,m;
vector< int > life[N+10];
int learn[N+10]; // Learning at each node
int total[N+10]; // Total learning from source

void takeInput()
{
    //Not handle Blank line before each test case scanf will do that for me ( I think ).
    for(int i=0; i<n; i++) {
        scanf("%d", &learn[i]);
        life[i].clear();
    }
    for(int i=0, u, v; i<m; i++) {
        scanf("%d %d", &u, &v);
        life[u].push_back(v);
    }
    return;
}

void maxLearn()
{
    // Find maximum learning from source to each node and store it in total( Algo : BFS)
    queue< int > Q;
    memset(total, 0, sizeof(total));

    int u,v;

    Q.push(0);
    while( !Q.empty() ) {
        u = Q.front(); Q.pop();
        for(int i=0, l=life[u].size(); i<l; i++) {
            v = life[u][i];
            if(total[v] < (total[u]+learn[v]) ) {
                total[v] = total[u] + learn[v];
                Q.push(v);
            }
        }
    }
    return;
}

int main()
{
    //freopen("a.txt", "r", stdin);
    int *max_e;
    int kases; cin >>kases;
    for(int kase=1; kase<=kases; kase++) {
        scanf("%d %d", &n, &m);
        takeInput();
        maxLearn();
        max_e = max_element(total, total+n);
        printf("Case %d: %d %d\n", kase, *max_e, (max_e-total) );
    }

    return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA Live archivwe5818 : WA

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “ACM ICPC Archive Board”