답안 #1020130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020130 2024-07-11T15:21:22 Z alexdd Jail (JOI22_jail) C++17
72 / 100
5000 ms 924976 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> tree[120005],con[120005];
vector<int> son[120005],ton[120005];
pair<int,int> drum[120005];
int depth[120005],parent[120005],pos[120005],curpos,head[120005],siz[120005],cine[120005];
bool visited[120005];
void resetare()
{
    curpos=0;
    for(int i=1;i<=n;i++)
    {
        con[i].clear();
        tree[i].clear();
        son[i].clear();
        ton[i].clear();
        visited[i]=0;
    }
}

void dfs_tree(int nod)
{
    siz[nod]=1;
    for(auto adj:tree[nod])
    {
        if(adj!=parent[nod])
        {
            parent[adj]=nod;
            depth[adj]=depth[nod]+1;
            dfs_tree(adj);
            siz[nod]+=siz[adj];
        }
    }
}
void decompose(int nod, int chead)
{
    pos[nod]=++curpos;
    cine[pos[nod]]=nod;
    head[nod]=chead;
    int maxc=-1,heavy=-1;
    for(auto adj:tree[nod])
        if(adj!=parent[nod] && siz[adj]>maxc)
            maxc=siz[adj], heavy=adj;
    if(heavy!=-1)
        decompose(heavy,chead);
    for(auto adj:tree[nod])
        if(adj!=parent[nod] && adj!=heavy)
            decompose(adj,adj);
}


void baga_aint(int nod, int st, int dr, int le, int ri, int from)
{
    for(int i=le;i<=ri;i++)
    {
        for(auto x:son[cine[i]])
            con[x].push_back(from);
        for(auto x:ton[cine[i]])
            con[from].push_back(x);
    }
}
void baga_hld(int a, int b, int from)
{
    for(;head[a]!=head[b];b=parent[head[b]])
    {
        if(depth[head[a]]>depth[head[b]])
            swap(a,b);
        baga_aint(1,1,n,pos[head[b]],pos[b],from);
    }
    if(pos[a]>pos[b])
        swap(a,b);
    baga_aint(1,1,n,pos[a],pos[b],from);
}

vector<int> topo;
int topo_pos[120005];
void dfs_graph(int nod)
{
    visited[nod]=1;
    for(auto adj:con[nod])
        if(!visited[adj])
            dfs_graph(adj);
    topo.push_back(nod);
}
bool has_cycle()
{
    topo.clear();
    for(int i=1;i<=n;i++)
        if(!visited[i])
            dfs_graph(i);
    reverse(topo.begin(),topo.end());
    for(int i=0;i<topo.size();i++)
        topo_pos[topo[i]]=i;
    for(int i=0;i<topo.size();i++)
        for(auto x:con[topo[i]])
            if(topo_pos[x]<i)
                return 1;
    return 0;
}

signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        resetare();
        int a,b;
        for(int i=1;i<n;i++)
        {
            cin>>a>>b;
            tree[a].push_back(b);
            tree[b].push_back(a);
        }
        cin>>m;
        for(int i=1;i<=m;i++)
        {
            cin>>a>>b;
            drum[i]={a,b};
            son[a].push_back(i);
            ton[b].push_back(i);
        }
        dfs_tree(1);
        decompose(1,1);
        for(int i=1;i<=m;i++)
        {
            baga_hld(drum[i].first,drum[i].second,i);
        }

        if(has_cycle()) cout<<"No\n";
        else cout<<"Yes\n";
    }
    return 0;
}

Compilation message

jail.cpp: In function 'bool has_cycle()':
jail.cpp:93:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for(int i=0;i<topo.size();i++)
      |                 ~^~~~~~~~~~~~
jail.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i=0;i<topo.size();i++)
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11612 KB Output is correct
2 Correct 5 ms 11644 KB Output is correct
3 Correct 5 ms 11612 KB Output is correct
4 Correct 10 ms 12124 KB Output is correct
5 Correct 16 ms 12548 KB Output is correct
6 Correct 5 ms 11608 KB Output is correct
7 Correct 5 ms 11612 KB Output is correct
8 Correct 6 ms 11760 KB Output is correct
9 Correct 51 ms 15956 KB Output is correct
10 Correct 117 ms 31652 KB Output is correct
11 Correct 8 ms 11868 KB Output is correct
12 Correct 26 ms 12800 KB Output is correct
13 Correct 108 ms 64620 KB Output is correct
14 Correct 134 ms 78332 KB Output is correct
15 Execution timed out 5084 ms 924976 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11608 KB Output is correct
2 Correct 5 ms 11608 KB Output is correct
3 Correct 5 ms 11612 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 5 ms 11832 KB Output is correct
6 Correct 5 ms 11612 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 6 ms 11828 KB Output is correct
9 Correct 6 ms 11612 KB Output is correct
10 Correct 5 ms 11660 KB Output is correct
11 Correct 5 ms 11828 KB Output is correct
12 Correct 5 ms 11808 KB Output is correct
13 Correct 6 ms 11700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11608 KB Output is correct
2 Correct 5 ms 11608 KB Output is correct
3 Correct 5 ms 11612 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 5 ms 11832 KB Output is correct
6 Correct 5 ms 11612 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 6 ms 11828 KB Output is correct
9 Correct 6 ms 11612 KB Output is correct
10 Correct 5 ms 11660 KB Output is correct
11 Correct 5 ms 11828 KB Output is correct
12 Correct 5 ms 11808 KB Output is correct
13 Correct 6 ms 11700 KB Output is correct
14 Correct 5 ms 11612 KB Output is correct
15 Correct 5 ms 11780 KB Output is correct
16 Correct 5 ms 11612 KB Output is correct
17 Correct 5 ms 11612 KB Output is correct
18 Correct 6 ms 11612 KB Output is correct
19 Correct 5 ms 11612 KB Output is correct
20 Correct 6 ms 11608 KB Output is correct
21 Correct 5 ms 11740 KB Output is correct
22 Correct 5 ms 11608 KB Output is correct
23 Correct 6 ms 11612 KB Output is correct
24 Correct 5 ms 11612 KB Output is correct
25 Correct 5 ms 11836 KB Output is correct
26 Correct 5 ms 11612 KB Output is correct
27 Correct 6 ms 11612 KB Output is correct
28 Correct 5 ms 11748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11608 KB Output is correct
2 Correct 5 ms 11608 KB Output is correct
3 Correct 5 ms 11612 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 5 ms 11832 KB Output is correct
6 Correct 5 ms 11612 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 6 ms 11828 KB Output is correct
9 Correct 6 ms 11612 KB Output is correct
10 Correct 5 ms 11660 KB Output is correct
11 Correct 5 ms 11828 KB Output is correct
12 Correct 5 ms 11808 KB Output is correct
13 Correct 6 ms 11700 KB Output is correct
14 Correct 5 ms 11612 KB Output is correct
15 Correct 5 ms 11780 KB Output is correct
16 Correct 5 ms 11612 KB Output is correct
17 Correct 5 ms 11612 KB Output is correct
18 Correct 6 ms 11612 KB Output is correct
19 Correct 5 ms 11612 KB Output is correct
20 Correct 6 ms 11608 KB Output is correct
21 Correct 5 ms 11740 KB Output is correct
22 Correct 5 ms 11608 KB Output is correct
23 Correct 6 ms 11612 KB Output is correct
24 Correct 5 ms 11612 KB Output is correct
25 Correct 5 ms 11836 KB Output is correct
26 Correct 5 ms 11612 KB Output is correct
27 Correct 6 ms 11612 KB Output is correct
28 Correct 5 ms 11748 KB Output is correct
29 Correct 6 ms 11864 KB Output is correct
30 Correct 6 ms 11864 KB Output is correct
31 Correct 6 ms 11892 KB Output is correct
32 Correct 6 ms 11604 KB Output is correct
33 Correct 5 ms 11612 KB Output is correct
34 Correct 6 ms 11612 KB Output is correct
35 Correct 6 ms 11904 KB Output is correct
36 Correct 6 ms 11868 KB Output is correct
37 Correct 5 ms 11612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11608 KB Output is correct
2 Correct 5 ms 11608 KB Output is correct
3 Correct 5 ms 11612 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 5 ms 11832 KB Output is correct
6 Correct 5 ms 11612 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 6 ms 11828 KB Output is correct
9 Correct 6 ms 11612 KB Output is correct
10 Correct 5 ms 11660 KB Output is correct
11 Correct 5 ms 11828 KB Output is correct
12 Correct 5 ms 11808 KB Output is correct
13 Correct 6 ms 11700 KB Output is correct
14 Correct 5 ms 11612 KB Output is correct
15 Correct 5 ms 11780 KB Output is correct
16 Correct 5 ms 11612 KB Output is correct
17 Correct 5 ms 11612 KB Output is correct
18 Correct 6 ms 11612 KB Output is correct
19 Correct 5 ms 11612 KB Output is correct
20 Correct 6 ms 11608 KB Output is correct
21 Correct 5 ms 11740 KB Output is correct
22 Correct 5 ms 11608 KB Output is correct
23 Correct 6 ms 11612 KB Output is correct
24 Correct 5 ms 11612 KB Output is correct
25 Correct 5 ms 11836 KB Output is correct
26 Correct 5 ms 11612 KB Output is correct
27 Correct 6 ms 11612 KB Output is correct
28 Correct 5 ms 11748 KB Output is correct
29 Correct 6 ms 11864 KB Output is correct
30 Correct 6 ms 11864 KB Output is correct
31 Correct 6 ms 11892 KB Output is correct
32 Correct 6 ms 11604 KB Output is correct
33 Correct 5 ms 11612 KB Output is correct
34 Correct 6 ms 11612 KB Output is correct
35 Correct 6 ms 11904 KB Output is correct
36 Correct 6 ms 11868 KB Output is correct
37 Correct 5 ms 11612 KB Output is correct
38 Correct 51 ms 15792 KB Output is correct
39 Correct 122 ms 31696 KB Output is correct
40 Correct 39 ms 14672 KB Output is correct
41 Correct 27 ms 13656 KB Output is correct
42 Correct 30 ms 14928 KB Output is correct
43 Correct 22 ms 13408 KB Output is correct
44 Correct 10 ms 12120 KB Output is correct
45 Correct 37 ms 20948 KB Output is correct
46 Correct 38 ms 20836 KB Output is correct
47 Correct 51 ms 25548 KB Output is correct
48 Correct 49 ms 25544 KB Output is correct
49 Correct 36 ms 21196 KB Output is correct
50 Correct 40 ms 21084 KB Output is correct
51 Correct 32 ms 22732 KB Output is correct
52 Correct 32 ms 22480 KB Output is correct
53 Correct 10 ms 12640 KB Output is correct
54 Correct 41 ms 20928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11612 KB Output is correct
2 Correct 5 ms 11612 KB Output is correct
3 Correct 5 ms 11608 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 10 ms 12120 KB Output is correct
6 Correct 5 ms 11612 KB Output is correct
7 Correct 5 ms 11612 KB Output is correct
8 Correct 5 ms 11612 KB Output is correct
9 Correct 5 ms 11612 KB Output is correct
10 Correct 5 ms 11700 KB Output is correct
11 Correct 5 ms 11612 KB Output is correct
12 Correct 5 ms 11868 KB Output is correct
13 Correct 18 ms 12280 KB Output is correct
14 Correct 23 ms 12636 KB Output is correct
15 Correct 20 ms 12376 KB Output is correct
16 Correct 48 ms 22472 KB Output is correct
17 Correct 135 ms 32872 KB Output is correct
18 Correct 332 ms 60480 KB Output is correct
19 Correct 50 ms 23248 KB Output is correct
20 Correct 52 ms 23244 KB Output is correct
21 Correct 50 ms 23248 KB Output is correct
22 Correct 107 ms 32716 KB Output is correct
23 Correct 88 ms 32576 KB Output is correct
24 Correct 86 ms 32668 KB Output is correct
25 Correct 100 ms 32712 KB Output is correct
26 Correct 94 ms 32488 KB Output is correct
27 Correct 118 ms 36432 KB Output is correct
28 Correct 122 ms 40524 KB Output is correct
29 Correct 130 ms 37612 KB Output is correct
30 Correct 72 ms 30132 KB Output is correct
31 Correct 77 ms 30856 KB Output is correct
32 Correct 81 ms 29380 KB Output is correct
33 Correct 80 ms 30668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11612 KB Output is correct
2 Correct 5 ms 11644 KB Output is correct
3 Correct 5 ms 11612 KB Output is correct
4 Correct 10 ms 12124 KB Output is correct
5 Correct 16 ms 12548 KB Output is correct
6 Correct 5 ms 11608 KB Output is correct
7 Correct 5 ms 11612 KB Output is correct
8 Correct 6 ms 11760 KB Output is correct
9 Correct 51 ms 15956 KB Output is correct
10 Correct 117 ms 31652 KB Output is correct
11 Correct 8 ms 11868 KB Output is correct
12 Correct 26 ms 12800 KB Output is correct
13 Correct 108 ms 64620 KB Output is correct
14 Correct 134 ms 78332 KB Output is correct
15 Execution timed out 5084 ms 924976 KB Time limit exceeded
16 Halted 0 ms 0 KB -