답안 #994304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994304 2024-06-07T10:32:00 Z UVince Jail (JOI22_jail) C++17
49 / 100
5000 ms 491640 KB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

#define int ll
void solve();

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

    int t=1;
    cin>>t;
    while (t--) solve();
    return 0;
}

const int maxn = 120'000;


vector<vector<int>> g(maxn);
vector<int> num(maxn);
int n,m;
vector<int> s(maxn),t(maxn);
vector<vector<int>> path(maxn);
vector<bool> has(maxn,false);

bool dfs (int v, int start, int par=-1){
    if (v==t[start]) return true;
    for (int to : g[v]){
        if (to==par) continue;
        if (dfs(to, start, v)){
            if (to==t[start]) return true;
            num[to]++;
            path[start].push_back(to);
            return true;
        }
    }
    return false;
}

void dolanc(){
    cin>>m;
    vector<int> lst(maxn,0);
    vector<int> rst(maxn,0);
    vector<pair<int,int>> srt;
    bool ans=true;
    for (int i = 1; i <= m; i++)
    {
        cin>>s[i]>>t[i];
        if (s[i]<t[i]) lst[t[i]]=i;
        else rst[t[i]]=i;
        if (s[i]<t[i]) srt.push_back({s[i], 0-t[i]});
        else srt.push_back({t[i], 0-s[i]});
    }
    sort(srt.begin(), srt.end());
    int mx=0;
    for (int i=1;i<=n;i++){
        if (lst[i]){
            if (mx>=i) ans=false;
        }
        else if (rst[i]){
            mx=max(mx, s[rst[i]]);
        }
    }

    stack<pair<int,int>> st;

    for (auto x: srt){
        int i=x.first;
        int j=0-x.second;
        while (!st.empty() && st.top().second<j) st.pop();
        if (!st.empty()) ans=false;
        st.push(make_pair(i,j));
    }

    if (ans){
        cout<<"Yes\n";
    }
    else {
        cout<<"No\n";
    }
}

void solve(){
    cin>>n;
    path.assign(maxn, {});
    num.assign(maxn,0);
    has.assign(maxn,false);
    g.assign(maxn,{});
    queue<int> q;
    bool lanc=true;
    for (int i = 1; i < n; i++)
    {
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
        if (a!=i || b!=i+1) lanc=false;
    }
    cin>>m;
    for (int i = 1; i <= m; i++)
    {
        cin>>s[i]>>t[i];
        dfs(s[i], i);
        q.push(i);
        has[s[i]]=true;
    }
    bool change=true;
    while (change){
        change=false;
        int sz=q.size();
        for (int i=0;i<sz;i++){
            int cur=q.front();
            q.pop();
            bool rem=num[t[cur]];
            rem+=has[t[cur]];

            for (int j : path[cur]){
                if (has[j]) rem=true;
            }
            if (rem) {
                q.push(cur);
                continue;
            }
            change=true;
            has[s[cur]]=false;
            for (int j : path[cur]){
                num[j]--;
            }
        }
    }
    if (q.empty()){
        cout<<"Yes\n";
    }
    else {
        cout<<"No\n";
    }
}

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:91:10: warning: variable 'lanc' set but not used [-Wunused-but-set-variable]
   91 |     bool lanc=true;
      |          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Correct 6 ms 8952 KB Output is correct
3 Correct 5 ms 8796 KB Output is correct
4 Correct 428 ms 8964 KB Output is correct
5 Correct 890 ms 8796 KB Output is correct
6 Correct 22 ms 8796 KB Output is correct
7 Correct 32 ms 8796 KB Output is correct
8 Correct 24 ms 9052 KB Output is correct
9 Correct 827 ms 38088 KB Output is correct
10 Incorrect 1744 ms 491640 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 22 ms 8972 KB Output is correct
4 Correct 22 ms 8968 KB Output is correct
5 Correct 41 ms 8796 KB Output is correct
6 Correct 22 ms 8796 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 22 ms 8864 KB Output is correct
9 Correct 25 ms 8796 KB Output is correct
10 Correct 26 ms 8796 KB Output is correct
11 Correct 20 ms 8972 KB Output is correct
12 Correct 23 ms 8796 KB Output is correct
13 Correct 36 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 22 ms 8972 KB Output is correct
4 Correct 22 ms 8968 KB Output is correct
5 Correct 41 ms 8796 KB Output is correct
6 Correct 22 ms 8796 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 22 ms 8864 KB Output is correct
9 Correct 25 ms 8796 KB Output is correct
10 Correct 26 ms 8796 KB Output is correct
11 Correct 20 ms 8972 KB Output is correct
12 Correct 23 ms 8796 KB Output is correct
13 Correct 36 ms 8796 KB Output is correct
14 Correct 7 ms 8796 KB Output is correct
15 Correct 11 ms 8952 KB Output is correct
16 Correct 21 ms 8796 KB Output is correct
17 Correct 24 ms 8968 KB Output is correct
18 Correct 35 ms 8952 KB Output is correct
19 Correct 21 ms 8944 KB Output is correct
20 Correct 22 ms 8976 KB Output is correct
21 Correct 27 ms 8796 KB Output is correct
22 Correct 24 ms 8988 KB Output is correct
23 Correct 20 ms 8952 KB Output is correct
24 Correct 22 ms 8796 KB Output is correct
25 Correct 26 ms 8796 KB Output is correct
26 Correct 24 ms 8944 KB Output is correct
27 Correct 22 ms 8792 KB Output is correct
28 Correct 23 ms 8944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 22 ms 8972 KB Output is correct
4 Correct 22 ms 8968 KB Output is correct
5 Correct 41 ms 8796 KB Output is correct
6 Correct 22 ms 8796 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 22 ms 8864 KB Output is correct
9 Correct 25 ms 8796 KB Output is correct
10 Correct 26 ms 8796 KB Output is correct
11 Correct 20 ms 8972 KB Output is correct
12 Correct 23 ms 8796 KB Output is correct
13 Correct 36 ms 8796 KB Output is correct
14 Correct 7 ms 8796 KB Output is correct
15 Correct 11 ms 8952 KB Output is correct
16 Correct 21 ms 8796 KB Output is correct
17 Correct 24 ms 8968 KB Output is correct
18 Correct 35 ms 8952 KB Output is correct
19 Correct 21 ms 8944 KB Output is correct
20 Correct 22 ms 8976 KB Output is correct
21 Correct 27 ms 8796 KB Output is correct
22 Correct 24 ms 8988 KB Output is correct
23 Correct 20 ms 8952 KB Output is correct
24 Correct 22 ms 8796 KB Output is correct
25 Correct 26 ms 8796 KB Output is correct
26 Correct 24 ms 8944 KB Output is correct
27 Correct 22 ms 8792 KB Output is correct
28 Correct 23 ms 8944 KB Output is correct
29 Correct 42 ms 9040 KB Output is correct
30 Correct 25 ms 8792 KB Output is correct
31 Correct 23 ms 9004 KB Output is correct
32 Correct 22 ms 9000 KB Output is correct
33 Correct 20 ms 8792 KB Output is correct
34 Correct 40 ms 8796 KB Output is correct
35 Correct 24 ms 9052 KB Output is correct
36 Correct 23 ms 8796 KB Output is correct
37 Correct 25 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 22 ms 8972 KB Output is correct
4 Correct 22 ms 8968 KB Output is correct
5 Correct 41 ms 8796 KB Output is correct
6 Correct 22 ms 8796 KB Output is correct
7 Correct 20 ms 8792 KB Output is correct
8 Correct 22 ms 8864 KB Output is correct
9 Correct 25 ms 8796 KB Output is correct
10 Correct 26 ms 8796 KB Output is correct
11 Correct 20 ms 8972 KB Output is correct
12 Correct 23 ms 8796 KB Output is correct
13 Correct 36 ms 8796 KB Output is correct
14 Correct 7 ms 8796 KB Output is correct
15 Correct 11 ms 8952 KB Output is correct
16 Correct 21 ms 8796 KB Output is correct
17 Correct 24 ms 8968 KB Output is correct
18 Correct 35 ms 8952 KB Output is correct
19 Correct 21 ms 8944 KB Output is correct
20 Correct 22 ms 8976 KB Output is correct
21 Correct 27 ms 8796 KB Output is correct
22 Correct 24 ms 8988 KB Output is correct
23 Correct 20 ms 8952 KB Output is correct
24 Correct 22 ms 8796 KB Output is correct
25 Correct 26 ms 8796 KB Output is correct
26 Correct 24 ms 8944 KB Output is correct
27 Correct 22 ms 8792 KB Output is correct
28 Correct 23 ms 8944 KB Output is correct
29 Correct 42 ms 9040 KB Output is correct
30 Correct 25 ms 8792 KB Output is correct
31 Correct 23 ms 9004 KB Output is correct
32 Correct 22 ms 9000 KB Output is correct
33 Correct 20 ms 8792 KB Output is correct
34 Correct 40 ms 8796 KB Output is correct
35 Correct 24 ms 9052 KB Output is correct
36 Correct 23 ms 8796 KB Output is correct
37 Correct 25 ms 8796 KB Output is correct
38 Correct 805 ms 38224 KB Output is correct
39 Incorrect 1823 ms 491464 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Correct 9 ms 8796 KB Output is correct
3 Correct 9 ms 8948 KB Output is correct
4 Correct 5 ms 8956 KB Output is correct
5 Correct 974 ms 9044 KB Output is correct
6 Correct 28 ms 8876 KB Output is correct
7 Correct 22 ms 8956 KB Output is correct
8 Correct 21 ms 8952 KB Output is correct
9 Correct 21 ms 8796 KB Output is correct
10 Correct 22 ms 9044 KB Output is correct
11 Correct 24 ms 8796 KB Output is correct
12 Correct 26 ms 8796 KB Output is correct
13 Correct 901 ms 9480 KB Output is correct
14 Correct 882 ms 9524 KB Output is correct
15 Correct 942 ms 9448 KB Output is correct
16 Execution timed out 5049 ms 15372 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Correct 6 ms 8952 KB Output is correct
3 Correct 5 ms 8796 KB Output is correct
4 Correct 428 ms 8964 KB Output is correct
5 Correct 890 ms 8796 KB Output is correct
6 Correct 22 ms 8796 KB Output is correct
7 Correct 32 ms 8796 KB Output is correct
8 Correct 24 ms 9052 KB Output is correct
9 Correct 827 ms 38088 KB Output is correct
10 Incorrect 1744 ms 491640 KB Output isn't correct
11 Halted 0 ms 0 KB -