답안 #339422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339422 2020-12-25T08:08:02 Z beksultan04 특수한 그래프 (IZhO13_specialg) C++14
0 / 100
4 ms 2796 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 == -1)
        if (!g[x].empty() && vis[g[x][0]] == 0){
            dfs(g[x][0],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: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)
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2796 KB Output isn't correct
2 Halted 0 ms 0 KB -