답안 #60793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60793 2018-07-24T17:01:50 Z Vahan 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2871 ms 46232 KB
#include "garden.h"
#include "gardenlib.h"
#include<vector>
#include<iostream>
using namespace std;
int p,u[400000],u1[400000],u2[400000],l1[400000],l2[400000];
int a[400000];
const int MAXN=400000;
vector<int> g[400005],inv[400000];
int dfs1(int v)
{
    if(v==2*p)
        return 1;
    if(u[v]==1)
        return -MAXN;
    u[v]=1;
    return dfs1(a[v])+1;
}
int dfs2(int v)
{
    if(v==2*p+1)
        return 1;
    if(u[v]==1)
        return -MAXN;
    u[v]=1;
    return dfs2(a[v])+1;
}
void dfs11(int v,int h)
{
    if(u1[v]==1)
        return;
    u1[v]=1;
    l1[v]=h;
    for(int i=0;i<inv[v].size();i++)
    {
        int to=inv[v][i];
        dfs11(to,h+1);
    }
}
void dfs22(int v,int h)
{
    if(u2[v]==1)
        return;
    u2[v]=1;
    l2[v]=h;
    for(int i=0;i<inv[v].size();i++)
    {
        int to=inv[v][i];
        dfs22(to,h+1);
    }
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    p=P;
    for(int i=0;i<M;i++)
    {
        g[R[i][0]].push_back(R[i][1]);
        g[R[i][1]].push_back(R[i][0]);
    }
    for(int i=0;i<N;i++)
    {
        if(g[i].size()==1)
        {
            if(g[g[i][0]][0]==i)
                a[2*i+1]=2*g[i][0]+1;
            else
                a[2*i+1]=2*g[i][0];
                a[2*i]=a[2*i+1];
        }
        else
        {
            if(g[g[i][0]][0]==i)
                a[2*i]=2*g[i][0]+1;
            else
                a[2*i]=2*g[i][0];
            if(g[g[i][1]][0]==i)
                a[2*i+1]=2*g[i][1]+1;
            else
                a[2*i+1]=2*g[i][1];
        }
    }
    for(int i=0;i<2*N;i++)
    {
        inv[a[i]].push_back(i);
        l1[i]=-1;
        l2[i]=-1;
    }
    int r1=dfs1(a[2*P]);
    if(r1<0)
        r1=0;
    for(int i=0;i<2*N;i++)
        u[i]=0;
    int r2=dfs2(a[2*P+1]);
    if(r2<0)
        r2=0;
    dfs11(2*p,0);
    dfs22(2*p+1,0);
    for(int i=0;i<Q;i++)
    {
        int an=0;
        for(int j=0;j<N;j++)
        {
            if(r1==0 && G[i]==l1[2*j])
                an++;
            else if(r1>0 && G[i]-l1[2*j]>=0 && (G[i]-l1[2*j])%r1==0 && l1[2*j]!=-1)
                an++;
            else if(r2==0 && G[i]==l2[2*j])
                an++;
            else if(r2>0 && G[i]-l2[2*j]>=0 && (G[i]-l2[2*j])%r2==0 && l2[2*j]!=-1)
                an++;
        }
        answer(an);
    }
}


Compilation message

garden.cpp: In function 'void dfs11(int, int)':
garden.cpp:34:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<inv[v].size();i++)
                 ~^~~~~~~~~~~~~~
garden.cpp: In function 'void dfs22(int, int)':
garden.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<inv[v].size();i++)
                 ~^~~~~~~~~~~~~~
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:66:13: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
             else
             ^~~~
garden.cpp:68:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
                 a[2*i]=a[2*i+1];
                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19368 KB Output is correct
2 Correct 21 ms 19240 KB Output is correct
3 Correct 21 ms 19328 KB Output is correct
4 Correct 20 ms 19224 KB Output is correct
5 Correct 20 ms 19156 KB Output is correct
6 Correct 21 ms 19420 KB Output is correct
7 Correct 20 ms 19232 KB Output is correct
8 Correct 21 ms 19276 KB Output is correct
9 Correct 23 ms 19468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19368 KB Output is correct
2 Correct 21 ms 19240 KB Output is correct
3 Correct 21 ms 19328 KB Output is correct
4 Correct 20 ms 19224 KB Output is correct
5 Correct 20 ms 19156 KB Output is correct
6 Correct 21 ms 19420 KB Output is correct
7 Correct 20 ms 19232 KB Output is correct
8 Correct 21 ms 19276 KB Output is correct
9 Correct 23 ms 19468 KB Output is correct
10 Correct 20 ms 19164 KB Output is correct
11 Correct 33 ms 22080 KB Output is correct
12 Correct 59 ms 24112 KB Output is correct
13 Correct 78 ms 37624 KB Output is correct
14 Correct 159 ms 35708 KB Output is correct
15 Correct 177 ms 36772 KB Output is correct
16 Correct 150 ms 31236 KB Output is correct
17 Correct 147 ms 30436 KB Output is correct
18 Correct 58 ms 24188 KB Output is correct
19 Correct 149 ms 36432 KB Output is correct
20 Correct 181 ms 37008 KB Output is correct
21 Correct 142 ms 31468 KB Output is correct
22 Correct 142 ms 30652 KB Output is correct
23 Correct 156 ms 37236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19368 KB Output is correct
2 Correct 21 ms 19240 KB Output is correct
3 Correct 21 ms 19328 KB Output is correct
4 Correct 20 ms 19224 KB Output is correct
5 Correct 20 ms 19156 KB Output is correct
6 Correct 21 ms 19420 KB Output is correct
7 Correct 20 ms 19232 KB Output is correct
8 Correct 21 ms 19276 KB Output is correct
9 Correct 23 ms 19468 KB Output is correct
10 Correct 20 ms 19164 KB Output is correct
11 Correct 33 ms 22080 KB Output is correct
12 Correct 59 ms 24112 KB Output is correct
13 Correct 78 ms 37624 KB Output is correct
14 Correct 159 ms 35708 KB Output is correct
15 Correct 177 ms 36772 KB Output is correct
16 Correct 150 ms 31236 KB Output is correct
17 Correct 147 ms 30436 KB Output is correct
18 Correct 58 ms 24188 KB Output is correct
19 Correct 149 ms 36432 KB Output is correct
20 Correct 181 ms 37008 KB Output is correct
21 Correct 142 ms 31468 KB Output is correct
22 Correct 142 ms 30652 KB Output is correct
23 Correct 156 ms 37236 KB Output is correct
24 Correct 22 ms 19240 KB Output is correct
25 Correct 434 ms 22128 KB Output is correct
26 Correct 712 ms 24228 KB Output is correct
27 Correct 1589 ms 37704 KB Output is correct
28 Correct 2675 ms 36504 KB Output is correct
29 Correct 2813 ms 36404 KB Output is correct
30 Correct 1772 ms 31028 KB Output is correct
31 Correct 933 ms 29792 KB Output is correct
32 Correct 169 ms 23900 KB Output is correct
33 Correct 2631 ms 35264 KB Output is correct
34 Correct 2803 ms 35932 KB Output is correct
35 Correct 1275 ms 30624 KB Output is correct
36 Correct 950 ms 29552 KB Output is correct
37 Correct 2871 ms 36092 KB Output is correct
38 Correct 2859 ms 46232 KB Output is correct