Submission #1020127

# Submission time Handle Problem Language Result Execution time Memory
1020127 2024-07-11T15:19:49 Z alexdd Jail (JOI22_jail) C++17
72 / 100
5000 ms 950652 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]])
            if(x!=from)
                con[x].push_back(from);
        for(auto x:ton[cine[i]])
            if(x!=from)
                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: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++)
      |                 ~^~~~~~~~~~~~
jail.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i=0;i<topo.size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11608 KB Output is correct
2 Correct 5 ms 11740 KB Output is correct
3 Correct 4 ms 11612 KB Output is correct
4 Correct 10 ms 12124 KB Output is correct
5 Correct 22 ms 12416 KB Output is correct
6 Correct 7 ms 11608 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 5 ms 11868 KB Output is correct
9 Correct 61 ms 15836 KB Output is correct
10 Correct 117 ms 31692 KB Output is correct
11 Correct 7 ms 11868 KB Output is correct
12 Correct 27 ms 12632 KB Output is correct
13 Correct 106 ms 63952 KB Output is correct
14 Correct 137 ms 78028 KB Output is correct
15 Execution timed out 5096 ms 950652 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11612 KB Output is correct
2 Correct 5 ms 11612 KB Output is correct
3 Correct 5 ms 11704 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 6 ms 11612 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 11836 KB Output is correct
11 Correct 5 ms 11612 KB Output is correct
12 Correct 4 ms 11820 KB Output is correct
13 Correct 5 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11612 KB Output is correct
2 Correct 5 ms 11612 KB Output is correct
3 Correct 5 ms 11704 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 6 ms 11612 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 11836 KB Output is correct
11 Correct 5 ms 11612 KB Output is correct
12 Correct 4 ms 11820 KB Output is correct
13 Correct 5 ms 11612 KB Output is correct
14 Correct 5 ms 11608 KB Output is correct
15 Correct 3 ms 11612 KB Output is correct
16 Correct 5 ms 11612 KB Output is correct
17 Correct 6 ms 11816 KB Output is correct
18 Correct 5 ms 11612 KB Output is correct
19 Correct 4 ms 11612 KB Output is correct
20 Correct 5 ms 11612 KB Output is correct
21 Correct 5 ms 11608 KB Output is correct
22 Correct 6 ms 11612 KB Output is correct
23 Correct 4 ms 11764 KB Output is correct
24 Correct 4 ms 11788 KB Output is correct
25 Correct 5 ms 11612 KB Output is correct
26 Correct 4 ms 11612 KB Output is correct
27 Correct 5 ms 11612 KB Output is correct
28 Correct 4 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11612 KB Output is correct
2 Correct 5 ms 11612 KB Output is correct
3 Correct 5 ms 11704 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 6 ms 11612 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 11836 KB Output is correct
11 Correct 5 ms 11612 KB Output is correct
12 Correct 4 ms 11820 KB Output is correct
13 Correct 5 ms 11612 KB Output is correct
14 Correct 5 ms 11608 KB Output is correct
15 Correct 3 ms 11612 KB Output is correct
16 Correct 5 ms 11612 KB Output is correct
17 Correct 6 ms 11816 KB Output is correct
18 Correct 5 ms 11612 KB Output is correct
19 Correct 4 ms 11612 KB Output is correct
20 Correct 5 ms 11612 KB Output is correct
21 Correct 5 ms 11608 KB Output is correct
22 Correct 6 ms 11612 KB Output is correct
23 Correct 4 ms 11764 KB Output is correct
24 Correct 4 ms 11788 KB Output is correct
25 Correct 5 ms 11612 KB Output is correct
26 Correct 4 ms 11612 KB Output is correct
27 Correct 5 ms 11612 KB Output is correct
28 Correct 4 ms 11612 KB Output is correct
29 Correct 5 ms 11868 KB Output is correct
30 Correct 5 ms 11612 KB Output is correct
31 Correct 6 ms 11868 KB Output is correct
32 Correct 6 ms 11612 KB Output is correct
33 Correct 5 ms 11844 KB Output is correct
34 Correct 5 ms 11612 KB Output is correct
35 Correct 6 ms 11868 KB Output is correct
36 Correct 6 ms 11848 KB Output is correct
37 Correct 6 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11612 KB Output is correct
2 Correct 5 ms 11612 KB Output is correct
3 Correct 5 ms 11704 KB Output is correct
4 Correct 5 ms 11612 KB Output is correct
5 Correct 6 ms 11612 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 11836 KB Output is correct
11 Correct 5 ms 11612 KB Output is correct
12 Correct 4 ms 11820 KB Output is correct
13 Correct 5 ms 11612 KB Output is correct
14 Correct 5 ms 11608 KB Output is correct
15 Correct 3 ms 11612 KB Output is correct
16 Correct 5 ms 11612 KB Output is correct
17 Correct 6 ms 11816 KB Output is correct
18 Correct 5 ms 11612 KB Output is correct
19 Correct 4 ms 11612 KB Output is correct
20 Correct 5 ms 11612 KB Output is correct
21 Correct 5 ms 11608 KB Output is correct
22 Correct 6 ms 11612 KB Output is correct
23 Correct 4 ms 11764 KB Output is correct
24 Correct 4 ms 11788 KB Output is correct
25 Correct 5 ms 11612 KB Output is correct
26 Correct 4 ms 11612 KB Output is correct
27 Correct 5 ms 11612 KB Output is correct
28 Correct 4 ms 11612 KB Output is correct
29 Correct 5 ms 11868 KB Output is correct
30 Correct 5 ms 11612 KB Output is correct
31 Correct 6 ms 11868 KB Output is correct
32 Correct 6 ms 11612 KB Output is correct
33 Correct 5 ms 11844 KB Output is correct
34 Correct 5 ms 11612 KB Output is correct
35 Correct 6 ms 11868 KB Output is correct
36 Correct 6 ms 11848 KB Output is correct
37 Correct 6 ms 11612 KB Output is correct
38 Correct 50 ms 15952 KB Output is correct
39 Correct 118 ms 31608 KB Output is correct
40 Correct 41 ms 14784 KB Output is correct
41 Correct 27 ms 13660 KB Output is correct
42 Correct 30 ms 15004 KB Output is correct
43 Correct 21 ms 13404 KB Output is correct
44 Correct 10 ms 12124 KB Output is correct
45 Correct 36 ms 20952 KB Output is correct
46 Correct 38 ms 20944 KB Output is correct
47 Correct 52 ms 25464 KB Output is correct
48 Correct 51 ms 25548 KB Output is correct
49 Correct 39 ms 21200 KB Output is correct
50 Correct 35 ms 21084 KB Output is correct
51 Correct 30 ms 22472 KB Output is correct
52 Correct 30 ms 22468 KB Output is correct
53 Correct 10 ms 12632 KB Output is correct
54 Correct 38 ms 20836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11612 KB Output is correct
2 Correct 5 ms 11740 KB Output is correct
3 Correct 4 ms 11608 KB Output is correct
4 Correct 4 ms 11608 KB Output is correct
5 Correct 8 ms 11868 KB Output is correct
6 Correct 4 ms 11672 KB Output is correct
7 Correct 5 ms 11612 KB Output is correct
8 Correct 4 ms 11608 KB Output is correct
9 Correct 4 ms 11740 KB Output is correct
10 Correct 5 ms 11612 KB Output is correct
11 Correct 5 ms 11612 KB Output is correct
12 Correct 9 ms 11760 KB Output is correct
13 Correct 17 ms 12380 KB Output is correct
14 Correct 23 ms 12540 KB Output is correct
15 Correct 20 ms 12380 KB Output is correct
16 Correct 43 ms 22100 KB Output is correct
17 Correct 139 ms 32184 KB Output is correct
18 Correct 324 ms 59108 KB Output is correct
19 Correct 49 ms 22732 KB Output is correct
20 Correct 57 ms 22800 KB Output is correct
21 Correct 49 ms 22736 KB Output is correct
22 Correct 107 ms 32204 KB Output is correct
23 Correct 90 ms 32328 KB Output is correct
24 Correct 88 ms 31824 KB Output is correct
25 Correct 88 ms 31816 KB Output is correct
26 Correct 89 ms 31820 KB Output is correct
27 Correct 123 ms 36432 KB Output is correct
28 Correct 114 ms 40480 KB Output is correct
29 Correct 115 ms 37476 KB Output is correct
30 Correct 70 ms 30156 KB Output is correct
31 Correct 70 ms 30876 KB Output is correct
32 Correct 79 ms 29440 KB Output is correct
33 Correct 68 ms 30664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11608 KB Output is correct
2 Correct 5 ms 11740 KB Output is correct
3 Correct 4 ms 11612 KB Output is correct
4 Correct 10 ms 12124 KB Output is correct
5 Correct 22 ms 12416 KB Output is correct
6 Correct 7 ms 11608 KB Output is correct
7 Correct 6 ms 11612 KB Output is correct
8 Correct 5 ms 11868 KB Output is correct
9 Correct 61 ms 15836 KB Output is correct
10 Correct 117 ms 31692 KB Output is correct
11 Correct 7 ms 11868 KB Output is correct
12 Correct 27 ms 12632 KB Output is correct
13 Correct 106 ms 63952 KB Output is correct
14 Correct 137 ms 78028 KB Output is correct
15 Execution timed out 5096 ms 950652 KB Time limit exceeded
16 Halted 0 ms 0 KB -