Submission #815049

# Submission time Handle Problem Language Result Execution time Memory
815049 2023-08-08T12:00:01 Z jajco Jail (JOI22_jail) C++17
61 / 100
5000 ms 24244 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){ // wczytanie grafu
            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,pn(n+1, -1),kn(n+1, -1);
        REP(i, m){ // wczytanie ziomow
            scanf("%d%d", &pocz[i], &kon[i]);
            pn[pocz[i]]=i,kn[kon[i]]=i;
        }

        std::vector <vi> dag(m, vi());
        vi ile(m);
        REP(k, m){ // generacja daga
            static std::function <bool(int, int, int, int)> DFS=[&](int i, int ojc, int d, int id){
                bool r=i==d;
                if (!r)
                    for (int j : pol[i])
                        if (j!=ojc)
                            if (r|=DFS(j, i, d, id))
                                break;
                if (r){
                    if (pn[i]>=0&&pn[i]!=id) // musimy byc po nim
                        dag[pn[i]].emplace_back(id),++ile[id];
                    if (kn[i]>=0&&kn[i]!=id) // musimy byc przed nim
                        dag[id].emplace_back(kn[i]),++ile[kn[i]];
                }
                return r;
            };
            DFS(pocz[k], pocz[k], kon[k], k);
        }
        bool czy=0;
        vi zer;
        REP(i, m)
            if (!ile[i])
                zer.emplace_back(i);
        int w=0;
        while (zer.size()){
            ++w;
            int p=zer.back();
            zer.pop_back();
            for (int i : dag[p])
                if (!--ile[i])
                    zer.emplace_back(i);
        }
        czy=w==m;
        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 11 ms 212 KB Output is correct
5 Correct 31 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 364 ms 2804 KB Output is correct
10 Correct 1723 ms 24244 KB Output is correct
11 Correct 6 ms 212 KB Output is correct
12 Correct 66 ms 328 KB Output is correct
13 Execution timed out 5044 ms 23956 KB Time limit exceeded
14 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 1 ms 328 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 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 1 ms 328 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 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 1 ms 328 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 5 ms 312 KB Output is correct
35 Correct 4 ms 360 KB Output is correct
36 Correct 2 ms 212 KB Output is correct
37 Correct 2 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 1 ms 328 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 5 ms 312 KB Output is correct
35 Correct 4 ms 360 KB Output is correct
36 Correct 2 ms 212 KB Output is correct
37 Correct 2 ms 212 KB Output is correct
38 Correct 340 ms 2796 KB Output is correct
39 Correct 1469 ms 24044 KB Output is correct
40 Correct 469 ms 1440 KB Output is correct
41 Correct 467 ms 688 KB Output is correct
42 Correct 242 ms 1696 KB Output is correct
43 Correct 53 ms 968 KB Output is correct
44 Correct 50 ms 340 KB Output is correct
45 Correct 1212 ms 7888 KB Output is correct
46 Correct 1264 ms 7896 KB Output is correct
47 Correct 594 ms 15300 KB Output is correct
48 Correct 684 ms 15344 KB Output is correct
49 Correct 715 ms 8196 KB Output is correct
50 Correct 735 ms 8196 KB Output is correct
51 Correct 216 ms 10336 KB Output is correct
52 Correct 256 ms 10216 KB Output is correct
53 Correct 43 ms 752 KB Output is correct
54 Correct 904 ms 7820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 Correct 6 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 3 ms 256 KB Output is correct
13 Correct 35 ms 304 KB Output is correct
14 Correct 47 ms 300 KB Output is correct
15 Correct 43 ms 280 KB Output is correct
16 Execution timed out 5101 ms 8468 KB Time limit exceeded
17 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 11 ms 212 KB Output is correct
5 Correct 31 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 364 ms 2804 KB Output is correct
10 Correct 1723 ms 24244 KB Output is correct
11 Correct 6 ms 212 KB Output is correct
12 Correct 66 ms 328 KB Output is correct
13 Execution timed out 5044 ms 23956 KB Time limit exceeded
14 Halted 0 ms 0 KB -