답안 #173952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173952 2020-01-05T20:36:00 Z awlintqaa Usmjeri (COCI17_usmjeri) C++14
28 / 140
2000 ms 262148 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 52224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 944 ms 121756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 248 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 250 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 250 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 258 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1211 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2070 ms 172896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2072 ms 186464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2070 ms 171536 KB Time limit exceeded
2 Halted 0 ms 0 KB -