Thursday, June 1, 2017

UVa 10685 - Nature


//aarifshuvo   ``CSEJU

#include <bits/stdc++.h>
#define ll long long
#define SZ(x) ((int)(x).size())
#define scl(x) scanf("%lld", &x)
#define scll(x,y) scanf("%lld %lld", &x, &y)
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
#define REV(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define pri(a) cout<<a<<endl
#define prii(a,b) cout<<a<<" "<<b<<endl
using namespace std;

ll c,r;
map<string,string> par;
map<string,int> cnt;

string sa, sb;

string findr(string s)
{
    if(par[s]=="") return s;

    string x = findr(par[s]);
    par[s] = x;
    return x;
}

int main()
{
    bool fl = 0;

    while(scll(c,r)==2 and c+r)
    {
        ll mx = 0;
        if(fl) printf("\n"), fl = 1;

        while(c--)
        {
            cin>>sa;
            cnt[sa]=1;
        }

        while(r--)
        {
            cin>>sa>>sb;

            string u = findr(sa), v = findr(sb);

            if(u!=v)
            {
                par[v] = u;
                cnt[u] = cnt[u] + cnt[v];
            }
            mx = max(mx, (ll)cnt[u]);
        }
        printf("%lld\n", mx);
        par.clear();
        cnt.clear();
    }
    return 0;
}

/// ideas (unsorted)


nature chain

if predator then same chain
find out the largest alimantery chain

maybe, the're trying to get the largest grp of the graph

okay ..

nodes c, edge r (5k)

first take all nodes (strings)
then get the edges each with two nodes
(par[first] = second;)

blank line btwn inputs

same as uva virtual frinds 11503

just dont print, take max each time finally print the mx

terminates with r0 c0

No comments:

Post a Comment