Submission #585689

# Submission time Handle Problem Language Result Execution time Memory
585689 2022-06-29T08:24:33 Z 조영욱(#8387) Star Trek (CEOI20_startrek) C++17
23 / 100
1000 ms 14016 KB
#include <bits/stdc++.h>
using namespace std;

int n;
long long d;
const int mod=1e9+7;

long long fastpow(long long a,long long b) {
    if (b==0) {
        return 1;
    }
    if (b%2==1) {
        return (fastpow(a,b-1)*a)%mod;
    }
    long long half=fastpow(a,b/2);
    return (half*half)%mod;
}

vector<int> adj[100001];
int dp[100001];
int dp1[100001];
int dep[100001];
int deg[1001];

void dfs1(int v,int prev) {
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (nt==prev){
            continue;
        }
        dep[nt]=dep[v]+1;
        dfs1(nt,v);
        deg[v]++;
        if (dp[nt]==0) {
            dp[v]++;
        }
    }
}

void dfs2(int v,int prev) {
    if (prev==0) {
        dp1[v]=1;
    }
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (nt==prev) {
            continue;
        }
        if (dp[nt]==0&&dp[v]>1) {
            dp1[nt]=0;
        }
        else if (dp[nt]>0&&dp[v]>0) {
            dp1[nt]=0;
        }
        else {
            dp1[nt]=2-dp1[v];
        }
        dfs2(nt,v);
    }
}

void dfs3(int v,int prev) {
    if (prev==0) {
        dp1[v]=0;
    }
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (nt==prev) {
            continue;
        }
        if (dp[nt]==0&&dp[v]>1) {
            dp1[nt]=0;
        }
        else if (dp[nt]>0&&dp[v]>0) {
            dp1[nt]=0;
        }
        else {
            dp1[nt]=1-dp1[v];
        }
        dfs3(nt,v);
    }
}

    long long d1,d2,d3,d4;
    long long one,two,three,four;

int main(void) {
    scanf("%d %lld",&n,&d);
    for(int i=1;i<n;i++) {
        int u,v;
        scanf("%d %d",&u,&v);
adj[u].push_back(v);
adj[v].push_back(u);
    }
    long long s=0;
dfs1(1,0);
dfs3(1,0);
for(int i=1;i<=n;i++)  if (dp[i]!=0||dp1[i]!=0) { s++;}
//printf("%lld\n",s);
    for(int i=1;i<=n;i++) {
        memset(dp,0,sizeof(dp));
        memset(dp1,0,sizeof(dp1));
        memset(deg,0,sizeof(deg));
        dep[i]=0;
        dfs1(i,0);
        dfs2(i,0);
        for(int j=1;j<=n;j++) {
            if (dp[j]>0) {
                d1++;
if (j==1) one++;
            }
            else if (i==j) {
                d3++;
if (j==1) three++;
            }
            else if (dp1[j]==2) {
                d1++;
if (j==1) one++;
            }
            else if (dp1[j]==0) {
                d2++;
if (j==1) two++;
            }
            else {
                if (dep[i]%2==dep[j]%2) {
                    d3++;
if (j==1) three++;
                }
                else {
                    d4++;
if (j==1) four++;
                }
            }
//printf("%d %d %d %d %d %d\n",i,j,one,two,three,four);
        }
    }
//printf("%lld %lld %lld %lld\n",one,two,three,four);
    long long ret=n*one+four*s+three*(n-s);
    printf("%lld",ret%mod);
}

Compilation message

startrek.cpp: In function 'void dfs1(int, int)':
startrek.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
startrek.cpp: In function 'void dfs2(int, int)':
startrek.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
startrek.cpp: In function 'void dfs3(int, int)':
startrek.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
startrek.cpp: In function 'int main()':
startrek.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     scanf("%d %lld",&n,&d);
      |     ~~~~~^~~~~~~~~~~~~~~~~
startrek.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Incorrect 65 ms 3460 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 4 ms 3412 KB Output is correct
4 Correct 4 ms 3412 KB Output is correct
5 Correct 6 ms 3444 KB Output is correct
6 Correct 6 ms 3440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 4 ms 3412 KB Output is correct
4 Correct 4 ms 3412 KB Output is correct
5 Correct 6 ms 3444 KB Output is correct
6 Correct 6 ms 3440 KB Output is correct
7 Correct 73 ms 3524 KB Output is correct
8 Correct 67 ms 3540 KB Output is correct
9 Correct 59 ms 3460 KB Output is correct
10 Correct 60 ms 3460 KB Output is correct
11 Correct 64 ms 3476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 4 ms 3412 KB Output is correct
4 Correct 4 ms 3412 KB Output is correct
5 Correct 6 ms 3444 KB Output is correct
6 Correct 6 ms 3440 KB Output is correct
7 Correct 73 ms 3524 KB Output is correct
8 Correct 67 ms 3540 KB Output is correct
9 Correct 59 ms 3460 KB Output is correct
10 Correct 60 ms 3460 KB Output is correct
11 Correct 64 ms 3476 KB Output is correct
12 Execution timed out 1067 ms 14016 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 4 ms 3412 KB Output is correct
4 Correct 4 ms 3412 KB Output is correct
5 Correct 6 ms 3444 KB Output is correct
6 Correct 6 ms 3440 KB Output is correct
7 Correct 73 ms 3524 KB Output is correct
8 Correct 67 ms 3540 KB Output is correct
9 Correct 59 ms 3460 KB Output is correct
10 Correct 60 ms 3460 KB Output is correct
11 Correct 64 ms 3476 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Incorrect 73 ms 3412 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 4 ms 3412 KB Output is correct
3 Correct 4 ms 3412 KB Output is correct
4 Correct 4 ms 3412 KB Output is correct
5 Correct 6 ms 3444 KB Output is correct
6 Correct 6 ms 3440 KB Output is correct
7 Correct 73 ms 3524 KB Output is correct
8 Correct 67 ms 3540 KB Output is correct
9 Correct 59 ms 3460 KB Output is correct
10 Correct 60 ms 3460 KB Output is correct
11 Correct 64 ms 3476 KB Output is correct
12 Execution timed out 1067 ms 14016 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Incorrect 65 ms 3460 KB Output isn't correct
3 Halted 0 ms 0 KB -