Submission #547384

# Submission time Handle Problem Language Result Execution time Memory
547384 2022-04-10T15:07:25 Z duality Jail (JOI22_jail) C++17
61 / 100
5000 ms 33616 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int S[120000],T[120000];
vi adjList[120000];
vi adjList2[120000];
int parent[120000][17],depth[120000],disc[120000],fin[120000],num = 0;
int doDFS(int u,int p,int d) {
    parent[u][0] = p,depth[u] = d,disc[u] = num++;
    for (int v: adjList[u]) {
        if (v != p) doDFS(v,u,d+1);
    }
    fin[u] = num;
    return 0;
}
int logn;
int lca(int u,int v) {
    int i;
    if (depth[u] < depth[v]) swap(u,v);
    for (i = logn-1; i >= 0; i--) {
        if ((parent[u][i] != -1) && (depth[parent[u][i]] >= depth[v])) u = parent[u][i];
    }
    if (u == v) return u;
    for (i = logn-1; i >= 0; i--) {
        if (parent[u][i] != parent[v][i]) u = parent[u][i],v = parent[v][i];
    }
    return parent[u][0];
}
int anc(int u,int v) {
    return ((disc[v] >= disc[u]) && (disc[v] < fin[u]));
}
int onPath(int u,int v,int w,int l) {
    if (!anc(l,w)) return 0;
    return anc(w,u) || anc(w,v);
}
int visited[120000],no = 0;
int doDFS2(int u) {
    if (visited[u] != 0) {
        if (visited[u] == 1) no = 1;
        return 0;
    }

    visited[u] = 1;
    for (int v: adjList2[u]) doDFS2(v);
    visited[u] = 2;
    return 0;
}
int main() {
    int i,j;
    int Q,N,M,A,B;
    scanf("%d",&Q);
    while (Q--) {
        scanf("%d",&N);
        for (i = 0; i < N-1; i++) {
            scanf("%d %d",&A,&B);
            A--,B--;
            adjList[A].pb(B);
            adjList[B].pb(A);
        }
        scanf("%d",&M);
        for (i = 0; i < M; i++) scanf("%d %d",&S[i],&T[i]),S[i]--,T[i]--;

        num = 0,doDFS(0,-1,0);
        for (i = 1; (1 << i) < N; i++) {
            for (j = 0; j < N; j++) {
                if (parent[j][i-1] != -1) parent[j][i] = parent[parent[j][i-1]][i-1];
                else parent[j][i] = -1;
            }
        }
        logn = i;
        for (i = 0; i < M; i++) {
            int l = lca(S[i],T[i]);
            for (j = 0; j < M; j++) {
                if (i != j) {
                    if (onPath(S[i],T[i],S[j],l)) adjList2[j].pb(i);
                    if (onPath(S[i],T[i],T[j],l)) adjList2[i].pb(j);
                }
            }
        }
        fill(visited,visited+M,0),no = 0;
        for (i = 0; i < M; i++) {
            if (visited[i] == 0) doDFS2(i);
        }
        if (no) printf("No\n");
        else printf("Yes\n");

        for (i = 0; i < N; i++) adjList[i].clear(),adjList2[i].clear();
    }

    return 0;
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
jail.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~
jail.cpp:109:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |             scanf("%d %d",&A,&B);
      |             ~~~~~^~~~~~~~~~~~~~~
jail.cpp:114:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         scanf("%d",&M);
      |         ~~~~~^~~~~~~~~
jail.cpp:115:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         for (i = 0; i < M; i++) scanf("%d %d",&S[i],&T[i]),S[i]--,T[i]--;
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5972 KB Output is correct
4 Correct 14 ms 5992 KB Output is correct
5 Correct 25 ms 5992 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 8 ms 6104 KB Output is correct
9 Correct 90 ms 8940 KB Output is correct
10 Correct 57 ms 27852 KB Output is correct
11 Correct 10 ms 5972 KB Output is correct
12 Correct 70 ms 6100 KB Output is correct
13 Execution timed out 5067 ms 33616 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5884 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5956 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 5 ms 5972 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 4 ms 5972 KB Output is correct
13 Correct 4 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5884 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5956 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 5 ms 5972 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 4 ms 5972 KB Output is correct
13 Correct 4 ms 5972 KB Output is correct
14 Correct 3 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 4 ms 5972 KB Output is correct
17 Correct 4 ms 5972 KB Output is correct
18 Correct 4 ms 5972 KB Output is correct
19 Correct 3 ms 5972 KB Output is correct
20 Correct 4 ms 5972 KB Output is correct
21 Correct 4 ms 6008 KB Output is correct
22 Correct 4 ms 5972 KB Output is correct
23 Correct 4 ms 5972 KB Output is correct
24 Correct 4 ms 5972 KB Output is correct
25 Correct 4 ms 5972 KB Output is correct
26 Correct 3 ms 5972 KB Output is correct
27 Correct 5 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5884 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5956 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 5 ms 5972 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 4 ms 5972 KB Output is correct
13 Correct 4 ms 5972 KB Output is correct
14 Correct 3 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 4 ms 5972 KB Output is correct
17 Correct 4 ms 5972 KB Output is correct
18 Correct 4 ms 5972 KB Output is correct
19 Correct 3 ms 5972 KB Output is correct
20 Correct 4 ms 5972 KB Output is correct
21 Correct 4 ms 6008 KB Output is correct
22 Correct 4 ms 5972 KB Output is correct
23 Correct 4 ms 5972 KB Output is correct
24 Correct 4 ms 5972 KB Output is correct
25 Correct 4 ms 5972 KB Output is correct
26 Correct 3 ms 5972 KB Output is correct
27 Correct 5 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Correct 7 ms 6100 KB Output is correct
30 Correct 6 ms 5972 KB Output is correct
31 Correct 6 ms 6036 KB Output is correct
32 Correct 5 ms 6008 KB Output is correct
33 Correct 5 ms 5972 KB Output is correct
34 Correct 8 ms 5972 KB Output is correct
35 Correct 7 ms 5972 KB Output is correct
36 Correct 8 ms 6012 KB Output is correct
37 Correct 6 ms 5920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5884 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5956 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 5 ms 5972 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 4 ms 5972 KB Output is correct
13 Correct 4 ms 5972 KB Output is correct
14 Correct 3 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 4 ms 5972 KB Output is correct
17 Correct 4 ms 5972 KB Output is correct
18 Correct 4 ms 5972 KB Output is correct
19 Correct 3 ms 5972 KB Output is correct
20 Correct 4 ms 5972 KB Output is correct
21 Correct 4 ms 6008 KB Output is correct
22 Correct 4 ms 5972 KB Output is correct
23 Correct 4 ms 5972 KB Output is correct
24 Correct 4 ms 5972 KB Output is correct
25 Correct 4 ms 5972 KB Output is correct
26 Correct 3 ms 5972 KB Output is correct
27 Correct 5 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Correct 7 ms 6100 KB Output is correct
30 Correct 6 ms 5972 KB Output is correct
31 Correct 6 ms 6036 KB Output is correct
32 Correct 5 ms 6008 KB Output is correct
33 Correct 5 ms 5972 KB Output is correct
34 Correct 8 ms 5972 KB Output is correct
35 Correct 7 ms 5972 KB Output is correct
36 Correct 8 ms 6012 KB Output is correct
37 Correct 6 ms 5920 KB Output is correct
38 Correct 93 ms 8932 KB Output is correct
39 Correct 56 ms 27920 KB Output is correct
40 Correct 143 ms 7872 KB Output is correct
41 Correct 128 ms 6720 KB Output is correct
42 Correct 128 ms 8052 KB Output is correct
43 Correct 28 ms 6788 KB Output is correct
44 Correct 62 ms 6100 KB Output is correct
45 Correct 71 ms 19132 KB Output is correct
46 Correct 68 ms 19084 KB Output is correct
47 Correct 60 ms 22772 KB Output is correct
48 Correct 59 ms 22844 KB Output is correct
49 Correct 65 ms 19328 KB Output is correct
50 Correct 62 ms 19224 KB Output is correct
51 Correct 54 ms 20360 KB Output is correct
52 Correct 56 ms 20364 KB Output is correct
53 Correct 78 ms 6892 KB Output is correct
54 Correct 80 ms 19044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5972 KB Output is correct
4 Correct 3 ms 5972 KB Output is correct
5 Correct 9 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 3 ms 5972 KB Output is correct
8 Correct 3 ms 5972 KB Output is correct
9 Correct 3 ms 5972 KB Output is correct
10 Correct 3 ms 5972 KB Output is correct
11 Correct 3 ms 5972 KB Output is correct
12 Correct 7 ms 6016 KB Output is correct
13 Correct 60 ms 6012 KB Output is correct
14 Correct 48 ms 5972 KB Output is correct
15 Correct 44 ms 5972 KB Output is correct
16 Correct 2337 ms 19764 KB Output is correct
17 Execution timed out 5065 ms 20416 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5972 KB Output is correct
4 Correct 14 ms 5992 KB Output is correct
5 Correct 25 ms 5992 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 8 ms 6104 KB Output is correct
9 Correct 90 ms 8940 KB Output is correct
10 Correct 57 ms 27852 KB Output is correct
11 Correct 10 ms 5972 KB Output is correct
12 Correct 70 ms 6100 KB Output is correct
13 Execution timed out 5067 ms 33616 KB Time limit exceeded
14 Halted 0 ms 0 KB -