This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int ll
#define MAX 1000001
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << endl;\
}
#define outputvec(a){\
for(auto x:a){\
cout << (int)x << " ";\
}\
cout << endl;\
}
#define reset(a,n,v){\
for(int i=0;i<n;i++){\
a[i]=v;\
}\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
int n,q,t=1,m,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],d[MAX],e[MAX];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s[MAX],str[MAX];
//int e[1001][1001];
string s1,s2,s3;
const int mod = 998244353;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<vector<int>> g;
int res=0;
void dfs(int v,int prev){
a[v]=1;
for(auto x:g[v]){
if(x==prev){
continue;
}
dfs(x,v);
a[v]*=(a[x]+1);
a[v]%=MOD;
}
res+=a[v];
res%=MOD;
}
bool ok;
void dfs1(int v,int prev){
a[v]=1;
for(auto x:g[v]){
if(b[x]==0 || x==prev){
continue;
}
if(a[x]){
ok=false;
return;
}
dfs1(x,v);
}
}
void solve(){
cin >> n >> m;
g.clear();
g.resize(n);
for(int i=0;i<m;i++){
cin >> x >> y;
x--;
y--;
g[x].pb(y);
g[y].pb(x);
}
if(n<=20){
int res=0;
int h=(1<<n);
for(int i=1;i<h;i++){
int h1;
for(int j=0;j<n;j++){
if((i&(1<<j))){
b[j]=1;
h1=j;
}
}
ok=true;
dfs1(h1,-1);
for(int j=0;j<n;j++){
if(b[j]==1 && a[j]==0){
ok=false;
}
}
if(ok){
res++;
}
else{
}
for(int j=0;j<n;j++){
a[j]=b[j]=0;
}
}
cout << res << "\n";
return;
}
dfs(0,-1);
cout << res << "\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input13.txt","r",stdin);
//cin >> t;
ll cnt1=1;
while(t--){
solve();
cnt1++;
}
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:74:19: warning: 'h1' may be used uninitialized in this function [-Wmaybe-uninitialized]
74 | for(auto x:g[v]){
| ^
Main.cpp:100:17: note: 'h1' was declared here
100 | int h1;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |