답안 #875749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875749 2023-11-20T12:30:59 Z dimashhh Jail (JOI22_jail) C++17
0 / 100
10 ms 19848 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, MOD = 998244353;

vector<int> g[N], x[N], gt[N];
int timer = 0, tin[N], tout[N], n, m, s[N], t[N], pp[N], val[N], used[N];
void dfs(int v, int pr = 1)
{
    tin[v] = ++timer;
    pp[v] = pr;
    for (int to : g[v])
    {
        if (to == pr)
            continue;
        dfs(to, v);
    }
    tout[v] = ++timer;
}
bool is(int v, int u)
{
    return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
vector<int> path(int v,int u){
    vector<int> p(1,v);
    while(!is(v,u)){
        v = pp[v];
        p.push_back(v);
    }
    while(!is(u,v)){
        p.push_back(u);
        u = pp[u];
    }
    return p;
}
bool res = 1;
void dfs1(int v){
    used[v] = 1;
    for(int to:gt[v]){
        if(used[to] == 1){
            res =0 ;
        }
        if(!used[to]){
            dfs1(to);
        }
    }
    used[v] = 2;
}
void test()
{
    res = 1;
    timer = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        g[i].clear();
    for (int i = 1; i <= n - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1);
    cin >> m;
    for(int i = 1;i <= n;i++){
        val[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        gt[i].clear();
    }
    for (int i = 1; i <= m; ++i)
    {
        cin >> s[i] >> t[i];
        used[i] = 0;
        val[s[i]] = i;
    }
    for(int i = 1;i <= m;i++){
        for(int j:path(s[i],t[i])){
            int x = val[j];
            if(x && x != i){
                gt[x].push_back(i);
            }
        }
    }
    for(int i = 1;i <= m;i++){
        if(!used[i] && res){
            dfs1(i);
        }
    }
    cout << (res ? "Yes\n" : "No\n");
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        test();
    }
}

Compilation message

jail.cpp:92:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   92 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 4 ms 19808 KB Output is correct
4 Incorrect 10 ms 19848 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Incorrect 5 ms 19808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Incorrect 5 ms 19808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Incorrect 5 ms 19808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Incorrect 5 ms 19808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 4 ms 19844 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Incorrect 7 ms 19804 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 4 ms 19808 KB Output is correct
4 Incorrect 10 ms 19848 KB Output isn't correct
5 Halted 0 ms 0 KB -