답안 #884841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884841 2023-12-08T14:34:41 Z Ahmed57 Jail (JOI22_jail) C++17
0 / 100
5000 ms 1048576 KB
#include <bits/stdc++.h>
 
using namespace std;
int pr[120001],dep[120001],vis[120001];
vector<int> adj[120001];
void dfs(int i,int ppp){
    pr[i] = ppp;
    dep[i] = dep[ppp]+1;
    for(auto j:adj[i]){
        if(j==ppp)continue;
        dfs(j,i);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t;cin>>t;
    z:while(t--){
    int n;cin>>n;
    for(int i = 1;i<n;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1,0);
    int q;cin>>q;
    vector<pair<int,int>> qu;
    for(int i = 1;i<=q;i++){
        int a,b;
        cin>>a>>b;
        qu.push_back({a,b});
    }
    vector<int> tree[q+1];
    int deg[q+1] = {0};
    for(int i = 0;i<qu.size();i++){
        int x = qu[i].first , y = qu[i].second;
        while(x!=y){
            if(dep[x]<dep[y])swap(x,y);
            vis[x] = i+1;
            x = pr[x];
        }
        vis[x] = i+1;
        for(int j = 0;j<qu.size();j++){
            if(i==j)continue;
            if(vis[qu[j].first]==i+1&&vis[qu[j].second]==i+1){
                cout<<"No\n";
                goto z;
            }
            if(vis[qu[j].first]==i+1){
                tree[i+1].push_back(j+1);
                deg[j+1]++;
            }else if(vis[qu[j].second]==i+1){
                tree[j+1].push_back(i+1);
                deg[i+1]++;
            }
        }
    }
    int cnt = 0;queue<int> qe;
    for(int i = 1;i<=q;i++){
        if(deg[i]==0){
            qe.push(i);
        }
    }
    while(!qe.empty()){
        int x = qe.front();qe.pop();
        cnt++;
        for(auto j:tree[x]){
            deg[j]--;
            if(deg[j]==0){
                qe.push(j);
            }
        }
    }
    if(cnt==q)cout<<"Yes\n";
    else cout<<"No\n";
}
    return 0;
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 0;i<qu.size();i++){
      |                   ~^~~~~~~~~~
jail.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int j = 0;j<qu.size();j++){
      |                       ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Execution timed out 5087 ms 3164 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Execution timed out 5084 ms 3164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Execution timed out 5084 ms 3164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Execution timed out 5084 ms 3164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Execution timed out 5084 ms 3164 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Runtime error 832 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Execution timed out 5087 ms 3164 KB Time limit exceeded
5 Halted 0 ms 0 KB -