Submission #71485441


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 2000000000000000000;


signed main(){
    int n,m;cin>>n>>m;
    int c[n+1]={};
    vector<vector<int>>s(n+1,vector<int>(0));
    for(int i=0;i<m;i++){
        int u,v;cin>>u>>v;
        s[v].push_back(u);
    }
    int q;cin>>q;
    while(q--){
        int p,w;cin>>p>>w;
        if(p==2){
            if(c[w]==1){
                cout<<"Yes\n";
            }else{
                cout<<"No\n";
            }
        }else{
            if(c[w]==0){
                queue<int>que;
                que.push(w);
                while(!que.empty()){
                    int now=que.front();que.pop();
                    c[now]=1;
                    for(int i=0;i<s[now].size();i++){
                        if(c[s[now][i]]==0){
                            que.push(s[now][i]);
                        }
                    }
                }
            }
        }
    }
}

Submission Info

Submission Time
Task D - Reachability Query 2
User Sabakanmelm
Language C++23 (GCC 15.2.0)
Score 425
Code Size 995 Byte
Status AC
Exec Time 361 ms
Memory 22168 KiB

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:31:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                     for(int i=0;i<s[now].size();i++){
      |                                 ~^~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 1
AC × 30
Set Name Test Cases
Sample sample_01.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, sample_01.txt
Case Name Status Exec Time Memory
min.txt AC 2 ms 3588 KiB
random_01.txt AC 335 ms 18840 KiB
random_02.txt AC 338 ms 19000 KiB
random_03.txt AC 248 ms 8412 KiB
random_04.txt AC 301 ms 10924 KiB
random_05.txt AC 170 ms 4140 KiB
random_06.txt AC 156 ms 3664 KiB
random_07.txt AC 209 ms 6148 KiB
random_08.txt AC 335 ms 16436 KiB
random_09.txt AC 162 ms 5404 KiB
random_10.txt AC 176 ms 5816 KiB
random_11.txt AC 245 ms 10132 KiB
random_12.txt AC 298 ms 17648 KiB
random_13.txt AC 132 ms 6200 KiB
random_14.txt AC 107 ms 5132 KiB
random_15.txt AC 177 ms 10396 KiB
random_16.txt AC 213 ms 11724 KiB
random_17.txt AC 305 ms 17456 KiB
random_18.txt AC 330 ms 22168 KiB
random_19.txt AC 158 ms 3528 KiB
random_20.txt AC 194 ms 5032 KiB
random_21.txt AC 330 ms 18488 KiB
random_22.txt AC 329 ms 22128 KiB
random_23.txt AC 302 ms 19640 KiB
random_24.txt AC 325 ms 22060 KiB
random_25.txt AC 361 ms 22032 KiB
random_26.txt AC 359 ms 22056 KiB
random_27.txt AC 307 ms 21980 KiB
random_28.txt AC 256 ms 17456 KiB
sample_01.txt AC 1 ms 3392 KiB