Submission #339424

# Submission time Handle Problem Language Result Execution time Memory
339424 2020-12-25T08:17:39 Z beksultan04 Special graph (IZhO13_specialg) C++14
0 / 100
54 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,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;
    scan1(n)
    for (i=1;i<=n;++i){
        int x;
        scan1(x)
        if (x)g[i].pb(x);
    }
    scan1(m)
    while (m--){
        int t;
        scan1(t)
        if (t==1){
            int x;
            scan1(x)
            g[x].pop_back();
        }
        else {
            int x,y;
            scan2(x,y)
            ans=-1;
            dfs(x,y);
            cout <<ans<<'\n';
        }
    }



}






Compilation message

specialg.cpp: In function 'void dfs(long long int, long long int, long long int)':
specialg.cpp:30:19: 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]
   30 |     for (int i=0;i<g[x].size();++i){
      |                  ~^~~~~~~~~~~~
specialg.cpp: At global scope:
specialg.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      |      ^
specialg.cpp: In function 'int main()':
specialg.cpp:39:13: warning: unused variable 'j' [-Wunused-variable]
   39 |     int n,i,j,m;
      |             ^
specialg.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
specialg.cpp:40:5: note: in expansion of macro 'scan1'
   40 |     scan1(n)
      |     ^~~~~
specialg.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
specialg.cpp:43:9: note: in expansion of macro 'scan1'
   43 |         scan1(x)
      |         ^~~~~
specialg.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
specialg.cpp:46:5: note: in expansion of macro 'scan1'
   46 |     scan1(m)
      |     ^~~~~
specialg.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
specialg.cpp:49:9: note: in expansion of macro 'scan1'
   49 |         scan1(t)
      |         ^~~~~
specialg.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
specialg.cpp:52:13: note: in expansion of macro 'scan1'
   52 |             scan1(x)
      |             ^~~~~
specialg.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
specialg.cpp:57:13: note: in expansion of macro 'scan2'
   57 |             scan2(x,y)
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -