Submission #561248

# Submission time Handle Problem Language Result Execution time Memory
561248 2022-05-12T14:08:27 Z wiwiho Jail (JOI22_jail) C++14
61 / 100
5000 ms 263688 KB
#include <bits/stdc++.h>

#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define eb emplace_back
#define pob pop_back()
#define mp make_pair
#define F first
#define S second
#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}

using namespace std;

typedef long long ll;

using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int n;
vector<vector<int>> g;
vector<vector<int>> pass;

void init(){
    g.clear();
    g.resize(n + 1);
    pass.clear();
    pass.resize(n + 1);
}

bool dfs(int now, int p, int to, int id){
    if(now == to){
        pass[now].eb(id);
        return true;
    }
    for(int i : g[now]){
        if(i == p) continue;
        if(dfs(i, now, to, id)){
            pass[now].eb(id);
            return true;
        }
    }
    return false;
}

void solve(){
    
    cin >> n;
    init();

    for(int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        g[u].eb(v);
        g[v].eb(u);
    }

    int m;
    cin >> m;
    vector<int> s(m + 1), t(m + 1);
    for(int i = 1; i <= m; i++){
        cin >> s[i] >> t[i];
        dfs(s[i], s[i], t[i], i);
    }

    vector<vector<int>> tg(m + 1);
    vector<int> in(m + 1);
    for(int i = 1; i <= m; i++){
        for(int j : pass[s[i]]){
            if(i == j) continue;
            in[j]++;
            tg[i].eb(j);
        }
        for(int j : pass[t[i]]){
            if(i == j) continue;
            in[i]++;
            tg[j].eb(i);
        }
    }

    queue<int> q;
    for(int i = 1; i <= m; i++){
        if(in[i] == 0) q.push(i);
    }
    int cnt = 0;
    while(!q.empty()){
        int now = q.front();
        q.pop();
        cnt++;
        for(int i : tg[now]){
            in[i]--;
            if(in[i] == 0){
                q.push(i);
            }
        }
    }
    
    if(cnt == m) cout << "Yes\n";
    else cout << "No\n";

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T--) solve();

    return 0;
}
# 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 348 KB Output is correct
5 Correct 27 ms 468 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 376 ms 15192 KB Output is correct
10 Correct 2454 ms 263192 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 81 ms 1344 KB Output is correct
13 Execution timed out 5061 ms 26504 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 368 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 368 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 3 ms 336 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 328 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 368 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 3 ms 336 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 328 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 6 ms 596 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 4 ms 336 KB Output is correct
32 Correct 4 ms 368 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 368 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 3 ms 336 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 2 ms 328 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 6 ms 596 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 4 ms 336 KB Output is correct
32 Correct 4 ms 368 KB Output is correct
33 Correct 2 ms 336 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 353 ms 14732 KB Output is correct
39 Correct 2337 ms 263688 KB Output is correct
40 Correct 422 ms 4948 KB Output is correct
41 Correct 444 ms 1956 KB Output is correct
42 Correct 222 ms 5468 KB Output is correct
43 Correct 47 ms 2092 KB Output is correct
44 Correct 53 ms 752 KB Output is correct
45 Correct 1578 ms 11988 KB Output is correct
46 Correct 1530 ms 11944 KB Output is correct
47 Correct 787 ms 64144 KB Output is correct
48 Correct 851 ms 65472 KB Output is correct
49 Correct 1085 ms 14252 KB Output is correct
50 Correct 1026 ms 14380 KB Output is correct
51 Correct 219 ms 11696 KB Output is correct
52 Correct 235 ms 12444 KB Output is correct
53 Correct 44 ms 1188 KB Output is correct
54 Correct 1525 ms 11416 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 1 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 11 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 38 ms 820 KB Output is correct
14 Correct 49 ms 1068 KB Output is correct
15 Correct 49 ms 960 KB Output is correct
16 Execution timed out 5035 ms 11728 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 14 ms 348 KB Output is correct
5 Correct 27 ms 468 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 376 ms 15192 KB Output is correct
10 Correct 2454 ms 263192 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 81 ms 1344 KB Output is correct
13 Execution timed out 5061 ms 26504 KB Time limit exceeded
14 Halted 0 ms 0 KB -