Submission #339428

# Submission time Handle Problem Language Result Execution time Memory
339428 2020-12-25T08:19:03 Z beksultan04 Special graph (IZhO13_specialg) C++14
0 / 100
59 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-15
const int N = 1e5+12,INF=1e9+7;
vector <int> g[N];
int ans;
bool vis[N];
void dfs(int x,int y,int cnt=0){
    vis[x]=1;
    if (x == y){
        ans = cnt;
        ret ;
    }
    if (ans > 0 )ret ;
    for (int i=0;i<g[x].size();++i){
        dfs(g[x][i],y,cnt+1);
    }

    vis[x]=0;
}


main(){
    int n,i,j,m;
    cin>>n;
    for (i=1;i<=n;++i){
        int x;
        cin>>x;
        if (x)g[i].pb(x);
    }
    cin>>m;
    while (m--){
        int t;
        cin>>t;
        if (t==1){
            int x;
            cin>>x;
            g[x].pop_back();
        }
        else {
            int x,y;
            cin>>x>>y;
            ans=-1;
            dfs(x,y);
            cout <<ans<<'\n';
        }
    }



}






Compilation message

specialg.cpp: In function 'void dfs(int, int, int)':
specialg.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i=0;i<g[x].size();++i){
      |                  ~^~~~~~~~~~~~
specialg.cpp: At global scope:
specialg.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main(){
      |      ^
specialg.cpp: In function 'int main()':
specialg.cpp:40:13: warning: unused variable 'j' [-Wunused-variable]
   40 |     int n,i,j,m;
      |             ^
# Verdict Execution time Memory Grader output
1 Runtime error 59 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -