답안 #871581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871581 2023-11-11T06:53:23 Z Trisanu_Das Star Trek (CEOI20_startrek) C++17
30 / 100
1000 ms 15228 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n;
int cnt=0,idx=0,tmp=0;
int pw(int a,int b){
    int ans=1;
    while(b){
        if(b&1){
            ans=ans*a%mod;
        }
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
vector<vector<int>> adj;
vector<int> dp;
void dfs(int k,int pa){
    bool flag=0;
    for(int j:adj[k]){
        if(j==pa){
            continue;
        }
        dfs(j,k);
        if(dp[j]==0){
            flag=1;
        }
    }
    if(k==idx&&tmp==1){
        flag=1;
    }
    dp[k]=flag;
}
signed main(){
    cin>>n;
    int d;cin>>d;
    if(n==2){
        int p=pw(2,d*2);
        cout<<p<<endl;
        return 0;
    }
    adj.resize(n*2);
    for(int i=1;i<n;i++){
        int a,b;cin>>a>>b;a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        dp.assign(n,-1);
        dfs(i,i);
        if(dp[i]==1){
            cnt++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        idx=i;
        dp.assign(n,-1);
        tmp=0;
        dfs(0,0);
        if(dp[0]==1){
            ans+=cnt;
        }
        dp.assign(n,-1);
        tmp=1;
        dfs(0,0);
        if(dp[0]==1){
            ans+=n-cnt;
        }
    }
    cout<<ans%mod<<endl;
 
    return 0;}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 21 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 33 ms 536 KB Output is correct
8 Correct 45 ms 348 KB Output is correct
9 Correct 19 ms 436 KB Output is correct
10 Correct 23 ms 504 KB Output is correct
11 Correct 24 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 33 ms 536 KB Output is correct
8 Correct 45 ms 348 KB Output is correct
9 Correct 19 ms 436 KB Output is correct
10 Correct 23 ms 504 KB Output is correct
11 Correct 24 ms 436 KB Output is correct
12 Execution timed out 1012 ms 15228 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 33 ms 536 KB Output is correct
8 Correct 45 ms 348 KB Output is correct
9 Correct 19 ms 436 KB Output is correct
10 Correct 23 ms 504 KB Output is correct
11 Correct 24 ms 436 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Incorrect 21 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 33 ms 536 KB Output is correct
8 Correct 45 ms 348 KB Output is correct
9 Correct 19 ms 436 KB Output is correct
10 Correct 23 ms 504 KB Output is correct
11 Correct 24 ms 436 KB Output is correct
12 Execution timed out 1012 ms 15228 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 21 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -