Submission #842665

# Submission time Handle Problem Language Result Execution time Memory
842665 2023-09-03T08:09:12 Z SUNWOOOOOOOO Jail (JOI22_jail) C++17
0 / 100
1 ms 4956 KB
#include <bits/stdc++.h>
using namespace std;
using pint = array <int, 2>;
const int mxN = 120005;
vector <int> adj[mxN], v1, v2;
pint st[mxN];
int n, m, s1[mxN], s2[mxN];

int solve()
{
    sort(st + 1, st + m + 1);

    for (int i = 1; i <= m; i++){
        if (st[i][0] < st[i][1]) {
            v1.push_back(st[i][1]);
            s1[st[i][0]]++, s1[st[i][1] + 1]--;
        }
        else {
            v2.push_back(st[i][1]);
            s2[st[i][1]]++, s2[st[i][0] + 1]--;
        }
    }

    for (int i = 0; i < (int) v1.size() - 1; i++) if (v1[i] > v1[i + 1]) return 0;
    for (int i = 0; i < (int) v2.size() - 1; i++) if (v2[i] < v2[i + 1]) return 0;

    for (int i = 1; i <= n; i++) s1[i] += s1[i - 1];
    for (int i = 1; i <= n; i++) s2[i] += s2[i - 1];
    for (int i = 1; i <= n; i++) if (s1[i] && s2[i]) return 0;

    return 1;
}

int main()
{
    int q;
    scanf("%d", &q);
    while (q--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) adj[i].clear();
        for (int i = 0, a, b; i < n - 1; i++){
            scanf("%d %d", &a, &b);
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        scanf("%d", &m);
        for (int i = 1; i <= m; i++) {
            scanf("%d %d", &st[i][0], &st[i][1]);
        }
        if (solve()) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jail.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
jail.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
jail.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |             scanf("%d %d", &st[i][0], &st[i][1]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -