답안 #1082140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082140 2024-08-30T18:13:53 Z underwaterkillerwhale Jail (JOI22_jail) C++17
72 / 100
3686 ms 1048576 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
 
const int N = 3e5 + 7;
const int Mod = 1e9 + 7;
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 320;
 
int n, m, Q;
vector<int> ke[N], ke2[N];
int high[N], pa[N];
int S[N], E[N];
pii qr[N];
 
void pdfs (int u, int p) {
    high[u] = high[p] + 1;
    pa[u] = p;
    iter (&v, ke[u]) {
        if (v != p) pdfs(v, u);
    }
}
 
int num[N], low[N], del[N];
int time_dfs = 0;
bool ok = 1;
stack<int> st;
 
void dfs (int u) {
    num[u] = low[u] = ++time_dfs;
    st.push(u);
    iter (&v, ke2[u]) {
        if (del[v]) continue;
        if (!num[v]) {
            dfs(v);
            low[u] = min(low[u], low[v]);
        }
        else low[u] = min(low[u], num[v]);
    }
    if (num[u] == low[u]) {
        int v;
        int num = 0;
        do {
           v = st.top();
           st.pop();
           num ++;
           del[v] = 1;
        }while (v != u);
        if (num > 1) ok = 0;
    }
}
 
void solution () {
    time_dfs = 0;
    ok = 1;
    rep (i, 1, n) vector<int> ().swap(ke[i]), vector<int> ().swap(ke2[i]), E[i] = S[i] = num[i] = low[i] = del[i] = 0;
    cin >> n;
    rep (i, 1, n - 1) {
        int u, v;
        cin >> u>> v;
        ke[u].pb(v);
        ke[v].pb(u);
    }
    pdfs(1, 0);
    cin >> m;
    rep (i, 1, m) {
        cin >> qr[i].fs >> qr[i].se;
        S[qr[i].fs] = i;
        E[qr[i].se] = i;
    }
    rep (i, 1, m) {
        int u = qr[i].fs, v = qr[i].se;
        while (u != v) {
            if (high[u] > high[v]) swap(u, v);
            if (E[v]) ke2[i].pb(E[v]);
            if (S[v]) ke2[S[v]].pb(i);
            v = pa[v];
        }
        if (E[v]) ke2[i].pb(E[v]);
        if (S[v]) ke2[S[v]].pb(i);
    }
    rep (i, 1, m) if (!num[i]) dfs(i);
    if (ok) cout <<"Yes\n";
    else cout<<"No\n";
 
}
 
 
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +4
mình có muốn dùng mảng này không?
4 5
1 3
4 1
1 2
3 2
2 1
return->break
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 7 ms 14600 KB Output is correct
4 Correct 13 ms 14936 KB Output is correct
5 Correct 26 ms 15192 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 7 ms 14568 KB Output is correct
8 Correct 8 ms 14680 KB Output is correct
9 Correct 61 ms 17852 KB Output is correct
10 Correct 174 ms 27568 KB Output is correct
11 Correct 10 ms 14684 KB Output is correct
12 Correct 38 ms 15448 KB Output is correct
13 Correct 89 ms 58920 KB Output is correct
14 Correct 114 ms 72908 KB Output is correct
15 Runtime error 3686 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14644 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 9 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 8 ms 14500 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14644 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 9 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 8 ms 14500 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 7 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 7 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14428 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 7 ms 14428 KB Output is correct
21 Correct 9 ms 14428 KB Output is correct
22 Correct 7 ms 14508 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 7 ms 14548 KB Output is correct
25 Correct 7 ms 14428 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 7 ms 14428 KB Output is correct
28 Correct 6 ms 14384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14644 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 9 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 8 ms 14500 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 7 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 7 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14428 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 7 ms 14428 KB Output is correct
21 Correct 9 ms 14428 KB Output is correct
22 Correct 7 ms 14508 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 7 ms 14548 KB Output is correct
25 Correct 7 ms 14428 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 7 ms 14428 KB Output is correct
28 Correct 6 ms 14384 KB Output is correct
29 Correct 8 ms 14756 KB Output is correct
30 Correct 7 ms 14648 KB Output is correct
31 Correct 7 ms 14428 KB Output is correct
32 Correct 7 ms 14424 KB Output is correct
33 Correct 7 ms 14428 KB Output is correct
34 Correct 8 ms 14428 KB Output is correct
35 Correct 7 ms 14684 KB Output is correct
36 Correct 7 ms 14424 KB Output is correct
37 Correct 7 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14428 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 7 ms 14644 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 9 ms 14424 KB Output is correct
8 Correct 7 ms 14428 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 8 ms 14500 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 7 ms 14428 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 7 ms 14428 KB Output is correct
15 Correct 6 ms 14428 KB Output is correct
16 Correct 7 ms 14428 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 7 ms 14428 KB Output is correct
19 Correct 7 ms 14428 KB Output is correct
20 Correct 7 ms 14428 KB Output is correct
21 Correct 9 ms 14428 KB Output is correct
22 Correct 7 ms 14508 KB Output is correct
23 Correct 6 ms 14428 KB Output is correct
24 Correct 7 ms 14548 KB Output is correct
25 Correct 7 ms 14428 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 7 ms 14428 KB Output is correct
28 Correct 6 ms 14384 KB Output is correct
29 Correct 8 ms 14756 KB Output is correct
30 Correct 7 ms 14648 KB Output is correct
31 Correct 7 ms 14428 KB Output is correct
32 Correct 7 ms 14424 KB Output is correct
33 Correct 7 ms 14428 KB Output is correct
34 Correct 8 ms 14428 KB Output is correct
35 Correct 7 ms 14684 KB Output is correct
36 Correct 7 ms 14424 KB Output is correct
37 Correct 7 ms 14456 KB Output is correct
38 Correct 60 ms 17856 KB Output is correct
39 Correct 169 ms 27596 KB Output is correct
40 Correct 41 ms 16748 KB Output is correct
41 Correct 29 ms 15960 KB Output is correct
42 Correct 41 ms 16652 KB Output is correct
43 Correct 23 ms 15952 KB Output is correct
44 Correct 12 ms 14968 KB Output is correct
45 Correct 33 ms 21716 KB Output is correct
46 Correct 33 ms 21624 KB Output is correct
47 Correct 49 ms 24448 KB Output is correct
48 Correct 51 ms 24264 KB Output is correct
49 Correct 43 ms 21784 KB Output is correct
50 Correct 44 ms 21588 KB Output is correct
51 Correct 29 ms 22356 KB Output is correct
52 Correct 27 ms 22228 KB Output is correct
53 Correct 13 ms 15192 KB Output is correct
54 Correct 39 ms 21592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14428 KB Output is correct
2 Correct 6 ms 14424 KB Output is correct
3 Correct 8 ms 14484 KB Output is correct
4 Correct 9 ms 14428 KB Output is correct
5 Correct 11 ms 14684 KB Output is correct
6 Correct 7 ms 14428 KB Output is correct
7 Correct 7 ms 14428 KB Output is correct
8 Correct 6 ms 14380 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 7 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 24 ms 14940 KB Output is correct
14 Correct 27 ms 15440 KB Output is correct
15 Correct 27 ms 15192 KB Output is correct
16 Correct 42 ms 22340 KB Output is correct
17 Correct 78 ms 31568 KB Output is correct
18 Correct 187 ms 58812 KB Output is correct
19 Correct 38 ms 22864 KB Output is correct
20 Correct 37 ms 22864 KB Output is correct
21 Correct 41 ms 22800 KB Output is correct
22 Correct 66 ms 30416 KB Output is correct
23 Correct 57 ms 30104 KB Output is correct
24 Correct 59 ms 29644 KB Output is correct
25 Correct 54 ms 29772 KB Output is correct
26 Correct 58 ms 29784 KB Output is correct
27 Correct 75 ms 31988 KB Output is correct
28 Correct 81 ms 39368 KB Output is correct
29 Correct 84 ms 34260 KB Output is correct
30 Correct 58 ms 29392 KB Output is correct
31 Correct 70 ms 30464 KB Output is correct
32 Correct 63 ms 28116 KB Output is correct
33 Correct 57 ms 30576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14428 KB Output is correct
2 Correct 6 ms 14428 KB Output is correct
3 Correct 7 ms 14600 KB Output is correct
4 Correct 13 ms 14936 KB Output is correct
5 Correct 26 ms 15192 KB Output is correct
6 Correct 8 ms 14428 KB Output is correct
7 Correct 7 ms 14568 KB Output is correct
8 Correct 8 ms 14680 KB Output is correct
9 Correct 61 ms 17852 KB Output is correct
10 Correct 174 ms 27568 KB Output is correct
11 Correct 10 ms 14684 KB Output is correct
12 Correct 38 ms 15448 KB Output is correct
13 Correct 89 ms 58920 KB Output is correct
14 Correct 114 ms 72908 KB Output is correct
15 Runtime error 3686 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -