Cod sursa(job #1820032)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 1 decembrie 2016 03:13:09
Problema Lista lui Andrei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#define N 2005
#define LLi long long int
using namespace std;
ifstream f("nrcuv.in");
ofstream g("nrcuv.out");
LLi n,m,i,j;
string s,s1;
LLi const MOD=104659;
pair<char,char> Pair[N];
/*LLi pow1(LLi x,LLi y)
{
    LLi p=1;
    while(y>0)
    {
        if(y%2!=0)
        {
            p=p*x;
        }
        x=x*x;
        y=y/2;
    }
    return p;
}*/
LLI pow1( LLI number, LLI power )
{
    if ( power == 0 )
        return 1;
    if ( power == 1 )
        return number;
    if ( power % 2 )
        return ( pow1( number*number, (power-1) / 2) * number);
    else
        return pow1( number*number, power/2);
}
inline void read()
{
    f>>n>>m;
    for(int i=0;i<m;i++)
    {
        f>>Pair[i].first>>Pair[i].second;
        if(Pair[i].first>Pair[i].second)
            swap(Pair[i].first,Pair[i].second);
    }

    sort(Pair,Pair+m);
}
inline void rezolvare()
{
    int cont=0;
    for(int i=0;i<m;i++)
    {
        if(Pair[i].first!=Pair[i-1].first && Pair[i].second!=Pair[i-1].second)
            cont++;
        if(Pair[i].first!=Pair[i].second)
            cont++;
    }
    g<<(pow1(26,n)-((pow1(26,n-2)*(n-1)*cont)))%MOD;
}
int main()
{
    read();
    rezolvare();
}