#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <functional>
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <bitset>
using namespace std;
typedef unsigned long long LL;
int tab[200007];
vector < int > zarowki;
LL modulo=1000000007;
LL pot_szybkie(LL a, LL n)
{
if(n==0)
return 1;
if(n%2 == 1) //gdy n jest nieparzyste
return a * pot_szybkie(a, n - 1);
//żeby dwa razy nie wchodzić w tą samą rekurencję
__uint128_t w = pot_szybkie(a, n/2);
return (w * w)%modulo;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int ile, ile_w;
int liczba, w1, w2;
int blad=1;
int te_same=0;
int jedna=1;
cin >> ile >> ile_w;
for (int n=1; n<=ile; n++)
{
cin >> liczba;
zarowki.push_back(liczba);
}
//for (int n=0; n<ile; n++)
// cout << zarowki[n] << endl;
//cout << endl;
for (int n=0; n<ile_w; n++)
{
cin >> w1 >> w2;
// cout << w1-1 << " " << zarowki[w1-1] << " " << w2-1 << " " << zarowki[w2-1] << endl;
if (zarowki[w1-1]==zarowki[w2-1])
{
blad=0;
tab[w1]=tab[w1]+1;
tab[w2]=tab[w2]+1;
te_same=te_same+1;
}
// tab[w1]=tab[w1]+1;
// tab[w2]=tab[w2]+1;
}
for (int n=1; n<=ile; n++)
{
if (tab[n]>1)
jedna=0;
// cout << tab[n] << endl;
}
//cout << endl;
if (blad==1)
cout << 1;
else
if (jedna==1)
cout << LL(pot_szybkie(2, te_same));
else
cout << 4;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstdlib> #include <stack> #include <vector> #include <functional> #include <bits/stdc++.h> #include <sstream> #include <iomanip> #include <cmath> #include <cctype> #include <bitset> using namespace std; typedef unsigned long long LL; int tab[200007]; vector < int > zarowki; LL modulo=1000000007; LL pot_szybkie(LL a, LL n) { if(n==0) return 1; if(n%2 == 1) //gdy n jest nieparzyste return a * pot_szybkie(a, n - 1); //żeby dwa razy nie wchodzić w tą samą rekurencję __uint128_t w = pot_szybkie(a, n/2); return (w * w)%modulo; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int ile, ile_w; int liczba, w1, w2; int blad=1; int te_same=0; int jedna=1; cin >> ile >> ile_w; for (int n=1; n<=ile; n++) { cin >> liczba; zarowki.push_back(liczba); } //for (int n=0; n<ile; n++) // cout << zarowki[n] << endl; //cout << endl; for (int n=0; n<ile_w; n++) { cin >> w1 >> w2; // cout << w1-1 << " " << zarowki[w1-1] << " " << w2-1 << " " << zarowki[w2-1] << endl; if (zarowki[w1-1]==zarowki[w2-1]) { blad=0; tab[w1]=tab[w1]+1; tab[w2]=tab[w2]+1; te_same=te_same+1; } // tab[w1]=tab[w1]+1; // tab[w2]=tab[w2]+1; } for (int n=1; n<=ile; n++) { if (tab[n]>1) jedna=0; // cout << tab[n] << endl; } //cout << endl; if (blad==1) cout << 1; else if (jedna==1) cout << LL(pot_szybkie(2, te_same)); else cout << 4; return 0; } |
English