Submission #876229

# Submission time Handle Problem Language Result Execution time Memory
876229 2023-11-21T12:56:35 Z serkanrashid Jail (JOI22_jail) C++14
0 / 100
5000 ms 15392 KB
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

const int maxn = 12*1e4+5;

int q,n,m;
int inf = 1e9;
vector<int>g[maxn];
int s[maxn],t[maxn];
int used[maxn];
int want;

void precom()
{
    for(int i=1;i<=n;i++)
    {
        g[i].clear();
        used[i] = 0;
    }
}

void read()
{
    cin >> n;
    precom();
    int a,b;
    for(int i=1;i<n;i++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin >> m;
    for(int i=1;i<=m;i++)
    {
        cin >> s[i] >> t[i];
        used[s[i]] = inf;
    }
}

void dfs(int beg, int par)
{
    if(beg==want) want = -1;
    for(int nb:g[beg])
    {
        if(nb!=par&&!used[nb]) dfs(nb,beg);
    }
}

void solve()
{
    bool ans = true;
    for(int z=1;z<=m;z++)
    {
        bool f = false;
        for(int i=1;i<=m;i++)
        {
            if(used[s[i]]==inf&&!used[t[i]])
            {
                want = t[i];
                dfs(s[i],s[i]);
                if(want==-1)
                {
                    used[s[i]] = 0;
                    used[t[i]] = inf;
                    f = true;
                    break;
                }
            }
        }
        ans = (ans & f);
        if(!ans) break;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> q;
	for(int i=1;i<=q;i++)
    {
        read();
        solve();
    }
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 7 ms 4700 KB Output is correct
5 Correct 13 ms 5212 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4452 KB Output is correct
8 Correct 3 ms 4440 KB Output is correct
9 Correct 77 ms 5972 KB Output is correct
10 Correct 462 ms 15392 KB Output is correct
11 Correct 4 ms 4440 KB Output is correct
12 Correct 19 ms 5396 KB Output is correct
13 Execution timed out 5055 ms 10444 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4556 KB Output is correct
6 Correct 2 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 2 ms 4444 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4556 KB Output is correct
6 Correct 2 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 2 ms 4444 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4556 KB Output is correct
6 Correct 2 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 2 ms 4444 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4556 KB Output is correct
6 Correct 2 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 2 ms 4444 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 4 ms 4448 KB Output is correct
6 Incorrect 2 ms 4448 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 7 ms 4700 KB Output is correct
5 Correct 13 ms 5212 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4452 KB Output is correct
8 Correct 3 ms 4440 KB Output is correct
9 Correct 77 ms 5972 KB Output is correct
10 Correct 462 ms 15392 KB Output is correct
11 Correct 4 ms 4440 KB Output is correct
12 Correct 19 ms 5396 KB Output is correct
13 Execution timed out 5055 ms 10444 KB Time limit exceeded
14 Halted 0 ms 0 KB -