# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
791893 | Amylopectin | Star Trek (CEOI20_startrek) | C++14 | 1091 ms | 57224 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stdlib.h>
using namespace std;
const long long mxn = 1e6 + 10,mo = 1e9 + 7;
struct we
{
long long to,val[2][2],cur[2],num,ft;
we()
{
to = 0;
val[0][0] = -1;
val[0][1] = -1;
val[1][0] = -1;
val[1][1] = -1;
cur[0] = -1;
cur[1] = -1;
num = 0;
ft = -1;
}
we(long long cn,long long cnu,long long cft)
{
to = cn;
val[0][0] = -1;
val[0][1] = -1;
val[1][0] = -1;
val[1][1] = -1;
cur[0] = -1;
cur[1] = -1;
num = cnu;
ft = cft;
}
};
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].emplace_back(cm,i,0);
pat[cm].emplace_back(cn,i,1);
// 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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |