Submission #173952

#TimeUsernameProblemLanguageResultExecution timeMemory
173952awlintqaaUsmjeri (COCI17_usmjeri)C++14
28 / 140
2072 ms262148 KiB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #include <bits/stdc++.h> using namespace std; #define sqr 500 #define mid (l+r)/2 #define pb push_back #define ppb pop_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ins insert #define era erase #define C continue #define mem(dp,i) memset(dp,i,sizeof(dp)) #define mset multiset typedef long long ll; typedef long double ld; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; const ll mod=1000000007;//998244353; const ll inf=1e18*4; const ld pai=acos(-1); ll n,m; ll hight[300009],lev[300009],dp[300009][29],done[300009]; vll v[300009]; vpll g[300009]; void dfs1(ll node,ll p){ dp[node][0]=p; lev[node]=hight[node]=lev[p]+1; for(auto u:v[node]){ if(u==p)C; dfs1(u,node); } } void fill(){ for(ll j=1;j<20;j++){ for(ll i=0;i<n;i++){ dp[i][j]=dp[dp[i][j-1]][j-1]; } } } ll lca(ll a,ll b){ if(lev[a]<lev[b])swap(a,b); ll l=lev[a]-lev[b]; for(ll i=0;i<20;i++){ if((l&(1<<i)))a=dp[a][i]; } if(a==b)return a; for(ll i=19;i>=0;i--){ if(dp[a][i]!=dp[b][i]){ a=dp[a][i]; b=dp[b][i]; } } return dp[a][0]; } void add(ll a,ll b,ll c){ g[a].pb({b,c}); g[b].pb({a,c}); } void connect(ll node,ll p){ for(auto u:v[node]){ if(u==p)C; connect(u,node); hight[node]=min(hight[node],hight[u]); if(hight[u]<lev[node])add(u,node,0); } } ll check(ll node,ll c){ if(done[node]!=0)return (done[node]==c); done[node]=c; for(auto u:g[node]){ if(!check(u.fi,(c^u.se)))return 0; } return 1; } int main(){ cin>>n>>m; for(int i=0;i<n-1;i++){ ll a,b; cin>>a>>b; a--,b--; v[a].pb(b); v[b].pb(a); } dfs1(0,0); fill(); while(m--){ ll a,b,c; cin>>a>>b; a--,b--; c=lca(a,b); hight[a]=min(lev[c],hight[a]); hight[b]=min(lev[c],hight[b]); if(c!=a && c!=b)add(a,b,1); } connect(0,0); ll ans=1; for(int i=1;i<n;i++){ if(done[i])C; if(!check(i,1)){ cout<<0<<endl,exit(0); } ans*=2; ans%=mod; } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...