답안 #791881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791881 2023-07-24T12:08:35 Z Amylopectin Star Trek (CEOI20_startrek) C++14
23 / 100
213 ms 262144 KB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stdlib.h>
using namespace std;
const long long mxn = 1e7 + 10,mo = 1e9 + 7;
struct we
{
    long long to,val[2][2],cur[2],num,ft;
};
vector<struct we> pat[mxn] = {};
long long pid[mxn][2] = {},rwol,stt[mxn][2][3] = {};
long long re(long long cn,long long cidx,long long wh)
{
    long long i,j,fn,fm,ccur = -1,cva0 = 0,fidx,wop = (wh+1)&1,fcur,fva0,cva1 = 0,fva1;
    if(cidx != -1)
    {
        if(pat[cn][cidx].cur[wh] != -1)
        {
            return 0;
        }
    }
    for(i=0; i<pat[cn].size(); i++)
    {
        fn = pat[cn][i].to;
        if(i == cidx)
        {
            continue;
        }
        fidx = pid[pat[cn][i].num][(pat[cn][i].ft + 1)&1];
        re(fn,fidx,wop);
        fcur = pat[fn][fidx].cur[wop];
        fva0 = pat[fn][fidx].val[wop][0];
        fva1 = pat[fn][fidx].val[wop][1];
        if(wh == 0)
        {
            if(ccur == -1)
            {
                ccur = fcur;
                if(ccur < 2)
                {
                    cva0 = fva0;
                    cva1 = fva1;
                }
            }
            else 
            {
                if(fcur == 0)
                {
                    if(ccur != 0)
                    {
                        cva0 = fva0;
                        cva1 = 0;
                    }
                    else
                    {
                        cva0 = 0;
                    }
                    ccur = 0;
                    
                }
                else if(fcur == 1)
                {
                    if(ccur == 0)
                    {
                        // cva0 += fva0;
                        // cva += fva;
                    }
                    else if(ccur == 1)
                    {
                        cva1 += fva1;
                        cva0 = 0;
                    }
                    else 
                    {
                        ccur = 1;
                        cva1 += fva1;
                        cva0 = 0;
                    }
                }
            }
        }
        else 
        {
            if(ccur == -1)
            {
                ccur = fcur;
                if(ccur == 2)
                {
                    ccur = 1;
                }
                // if(ccur < 2)
                // {
                    // cva = fva;
                cva0 = fva0;
                cva1 = fva1;
                // }
            }
            else 
            {
                if(ccur == 0)
                {
                    if(fcur == 0)
                    {
                        cva0 += fva0;
                    }
                    else if(fcur == 1)
                    {
                        ccur = 1;
                        cva0 = fva0;
                        cva1 = fva1;
                    }
                    else 
                    {
                        cva0 = fva0;
                        cva1 = fva1;
                        ccur = 1;
                    }
                }
                else if(ccur == 1)
                {
                    if(fcur >= 1)
                    {
                        cva0 = 0;
                        cva1 = 0;
                        ccur = 2;
                    }
                }
            }
        }
    }
    if(wh == 0)
    {
        if(ccur == -1)
        {
            ccur = 1;
            cva1 = 1;
            cva0 = 0;
        }
        else if(ccur == 0)
        {
            // cva ++;
        }
        else if(ccur >= 1)
        {
            ccur = 1;
            cva1 ++;
        }
    }
    else 
    {
        if(ccur == -1)
        {
            ccur = 0;
            cva0 = 1;
        }
        else if(ccur == 0)
        {
            cva0 ++;
        }
    }
    if(cidx == -1)
    {
        stt[cn][wh][0] = cva0;
        stt[cn][wh][1] = cva1;
        stt[cn][wh][2] = ccur;
    }
    else 
    {
        pat[cn][cidx].cur[wh] = ccur;
        pat[cn][cidx].val[wh][0] = cva0;
        pat[cn][cidx].val[wh][1] = cva1;
    }
    return 0;
}
int main()
{
    // freopen("input1.txt","r",stdin);
    long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
    scanf("%lld %lld",&n,&m);
    for(i=1; i<n; i++)
    {
        scanf("%lld %lld",&cn,&cm);
        pid[i][0] = pat[cn].size();
        pid[i][1] = pat[cm].size();
        pat[cn].push_back({cm,{{-1,-1},{-1,-1}},{-1,-1},i,0});
        pat[cm].push_back({cn,{{-1,-1},{-1,-1}},{-1,-1},i,1});
    }
    uw = 0;
    cva0 = 0;
    cva1 = 0;
    for(i=1; i<=n; i++)
    {
        re(i,-1,0);
        re(i,-1,1);
        if(stt[i][0][2] == 0)
        {
            cva0 ++;
        }
        if(stt[i][1][2] == 0)
        {
            cva1 ++;
        }
    }
    ans = 0;
    if(stt[1][0][2] == 0)
    {
        ans = ((n - stt[1][0][0] - stt[1][0][1]) * n) % mo;
    }
    ans += stt[1][0][0] * cva0 + stt[1][0][1] * cva1;
    ans %= mo;
    printf("%lld\n",ans);
    return 0;
}

Compilation message

startrek.cpp: In function 'long long int re(long long int, long long int, long long int)':
startrek.cpp:25:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(i=0; i<pat[cn].size(); i++)
      |              ~^~~~~~~~~~~~~~~
startrek.cpp:17:17: warning: unused variable 'j' [-Wunused-variable]
   17 |     long long i,j,fn,fm,ccur = -1,cva0 = 0,fidx,wop = (wh+1)&1,fcur,fva0,cva1 = 0,fva1;
      |                 ^
startrek.cpp:17:22: warning: unused variable 'fm' [-Wunused-variable]
   17 |     long long i,j,fn,fm,ccur = -1,cva0 = 0,fidx,wop = (wh+1)&1,fcur,fva0,cva1 = 0,fva1;
      |                      ^~
startrek.cpp: In function 'int main()':
startrek.cpp:181:17: warning: unused variable 'j' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                 ^
startrek.cpp:181:29: warning: unused variable 'fn' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                             ^~
startrek.cpp:181:32: warning: unused variable 'fm' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                ^~
startrek.cpp:181:35: warning: unused variable 'cl' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                   ^~
startrek.cpp:181:38: warning: unused variable 'cr' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                      ^~
startrek.cpp:181:41: warning: unused variable 'su' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                         ^~
startrek.cpp:181:44: warning: unused variable 'cen' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                            ^~~
startrek.cpp:181:58: warning: unused variable 'ccur' [-Wunused-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                                          ^~~~
startrek.cpp:181:63: warning: variable 'uw' set but not used [-Wunused-but-set-variable]
  181 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen,cva0,cva1,ccur,uw,ans;
      |                                                               ^~
startrek.cpp:182:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  182 |     scanf("%lld %lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
startrek.cpp:185:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |         scanf("%lld %lld",&cn,&cm);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 235116 KB Output is correct
2 Incorrect 98 ms 235368 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 235084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 235176 KB Output is correct
2 Correct 109 ms 235152 KB Output is correct
3 Correct 111 ms 235092 KB Output is correct
4 Correct 98 ms 235096 KB Output is correct
5 Correct 97 ms 235160 KB Output is correct
6 Correct 97 ms 235060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 235176 KB Output is correct
2 Correct 109 ms 235152 KB Output is correct
3 Correct 111 ms 235092 KB Output is correct
4 Correct 98 ms 235096 KB Output is correct
5 Correct 97 ms 235160 KB Output is correct
6 Correct 97 ms 235060 KB Output is correct
7 Correct 104 ms 235436 KB Output is correct
8 Correct 98 ms 235484 KB Output is correct
9 Correct 103 ms 235296 KB Output is correct
10 Correct 99 ms 235384 KB Output is correct
11 Correct 102 ms 235376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 235176 KB Output is correct
2 Correct 109 ms 235152 KB Output is correct
3 Correct 111 ms 235092 KB Output is correct
4 Correct 98 ms 235096 KB Output is correct
5 Correct 97 ms 235160 KB Output is correct
6 Correct 97 ms 235060 KB Output is correct
7 Correct 104 ms 235436 KB Output is correct
8 Correct 98 ms 235484 KB Output is correct
9 Correct 103 ms 235296 KB Output is correct
10 Correct 99 ms 235384 KB Output is correct
11 Correct 102 ms 235376 KB Output is correct
12 Runtime error 213 ms 262144 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 235176 KB Output is correct
2 Correct 109 ms 235152 KB Output is correct
3 Correct 111 ms 235092 KB Output is correct
4 Correct 98 ms 235096 KB Output is correct
5 Correct 97 ms 235160 KB Output is correct
6 Correct 97 ms 235060 KB Output is correct
7 Correct 104 ms 235436 KB Output is correct
8 Correct 98 ms 235484 KB Output is correct
9 Correct 103 ms 235296 KB Output is correct
10 Correct 99 ms 235384 KB Output is correct
11 Correct 102 ms 235376 KB Output is correct
12 Correct 108 ms 235184 KB Output is correct
13 Incorrect 98 ms 235376 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 235176 KB Output is correct
2 Correct 109 ms 235152 KB Output is correct
3 Correct 111 ms 235092 KB Output is correct
4 Correct 98 ms 235096 KB Output is correct
5 Correct 97 ms 235160 KB Output is correct
6 Correct 97 ms 235060 KB Output is correct
7 Correct 104 ms 235436 KB Output is correct
8 Correct 98 ms 235484 KB Output is correct
9 Correct 103 ms 235296 KB Output is correct
10 Correct 99 ms 235384 KB Output is correct
11 Correct 102 ms 235376 KB Output is correct
12 Runtime error 213 ms 262144 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 235116 KB Output is correct
2 Incorrect 98 ms 235368 KB Output isn't correct
3 Halted 0 ms 0 KB -