Submission #814940

# Submission time Handle Problem Language Result Execution time Memory
814940 2023-08-08T11:16:47 Z jajco Jail (JOI22_jail) C++17
21 / 100
5000 ms 312 KB
#include <ios>
#include <vector>
#include <algorithm>
#include <functional>
#define REP(i, n) for (int i=0; i<n; ++i)
typedef std::vector <int> vi;
int main(){
    int q;
    scanf("%d", &q);
    while (q--){
        int n;
        scanf("%d", &n);
        std::vector <vi> pol(n+1, vi());
        REP(i, n-1){
            int p,k;
            scanf("%d%d", &p, &k);
            pol[p].emplace_back(k);
            pol[k].emplace_back(p);
        }
        int m;
        scanf("%d", &m);
        vi pocz(m),kon(m),perm;
        REP(i, m){
            scanf("%d%d", &pocz[i], &kon[i]);
            perm.emplace_back(i);
        }
        bool czy=0;
        while (1){
            std::vector <bool> zaj(n+1, 0);
            for (int i : pocz)
                zaj[i]=1;
            std::function <bool(int, int, int)> DFS=[&](
                    int i, int ojc, int d){
                if (i==d)
                    return true;
                bool r=0;
                for (int j : pol[i])
                    if (j!=ojc&&!zaj[j])
                        r|=DFS(j, i, d);
                return r;
            };
            bool w=1;
            for (int i : perm){
                if (!(w&=DFS(pocz[i], pocz[i], kon[i])))
                    break;
                zaj[pocz[i]]=0,zaj[kon[i]]=1;
            }
            czy|=w;
            if (czy||!std::next_permutation(perm.begin(), perm.end()))
                break;
        }
        printf(czy ? "Yes\n" : "No\n");
    }
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jail.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             scanf("%d%d", &p, &k);
      |             ~~~~~^~~~~~~~~~~~~~~~
jail.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
jail.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |             scanf("%d%d", &pocz[i], &kon[i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 14 ms 296 KB Output is correct
5 Correct 29 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 13 ms 212 KB Output is correct
8 Execution timed out 5051 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 11 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 18 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 12 ms 312 KB Output is correct
21 Correct 14 ms 212 KB Output is correct
22 Correct 10 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 65 ms 284 KB Output is correct
26 Correct 9 ms 308 KB Output is correct
27 Correct 12 ms 304 KB Output is correct
28 Correct 7 ms 280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 11 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 18 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 12 ms 312 KB Output is correct
21 Correct 14 ms 212 KB Output is correct
22 Correct 10 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 65 ms 284 KB Output is correct
26 Correct 9 ms 308 KB Output is correct
27 Correct 12 ms 304 KB Output is correct
28 Correct 7 ms 280 KB Output is correct
29 Execution timed out 5064 ms 212 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 11 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 18 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 12 ms 312 KB Output is correct
21 Correct 14 ms 212 KB Output is correct
22 Correct 10 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 65 ms 284 KB Output is correct
26 Correct 9 ms 308 KB Output is correct
27 Correct 12 ms 304 KB Output is correct
28 Correct 7 ms 280 KB Output is correct
29 Execution timed out 5064 ms 212 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Execution timed out 5020 ms 212 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 14 ms 296 KB Output is correct
5 Correct 29 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 13 ms 212 KB Output is correct
8 Execution timed out 5051 ms 212 KB Time limit exceeded
9 Halted 0 ms 0 KB -