답안 #47747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47747 2018-05-07T04:24:50 Z TheDarkning Bitaro’s Party (JOI18_bitaro) C++17
0 / 100
13 ms 9920 KB
/**
                  ▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
                  <⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>

            ♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
            ♔♕♖♗♘♙                             ♚♛♜♝♞♟
                      ˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
**/

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <assert.h>
#include <queue>
#include <string>
#include <memory.h>
#include <set>
#include <math.h>

#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define int long long
#define all(s) s.begin(), s.end()
#define ok puts("ok");

using namespace std;

const int N = 2e5 + 5;
const int inf = 1e9 + 7;

int n, m, q, a, b, t, y, x, ans, u[N], h[N], pr[N];
vector < int > g[N];

inline void dfs( int v, int d = 0 ){
    h[ v ] = d;
    for( int to : g[ v ] ){
        if( h[ to ] <= h[ v ] ){
            dfs( to, d + 1 );
        }
    }
}

main(){
    cin >> n >> m >> q;
    for( int i = 1; i <= m; i++ ){
        scanf("%d%d", &a, &b);
        if( b > a ){
            swap( a, b );
        }
        g[ a ].pb( b );
    }
    while( q-- ){
        scanf("%d%d", &t, &y );
        memset( u, 0, sizeof( u ) );
        memset( pr, 0, sizeof( pr ) );
        memset( h, 0, sizeof( h ) );
        for( int i = 1; i <= y; i++ ){
            scanf("%d", &x);
            pr[ x ] = 1;
        }
        dfs( t );
        int fl = 1;
        for( int i = 1; i <= n; i++ ){
            if( !pr[i] ){
                ans = max( ans, h[ i ] );
                fl = 0;
            }
        }
        if( ans ){
            cout << ans << endl;
        }
        else{
            if( fl ){
                puts("-1");
            }
            else{
                cout << ans << endl;
            }
        }
        ans = 0;
    }
}

Compilation message

bitaro.cpp:51:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
bitaro.cpp: In function 'int main()':
bitaro.cpp:54:29: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d%d", &a, &b);
                       ~~    ^
bitaro.cpp:54:29: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
bitaro.cpp:61:30: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d%d", &t, &y );
                       ~~     ^
bitaro.cpp:61:30: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
bitaro.cpp:66:27: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
             scanf("%d", &x);
                         ~~^
bitaro.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &t, &y );
         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:66:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 13 ms 9852 KB Output is correct
3 Correct 12 ms 9920 KB Output is correct
4 Incorrect 12 ms 9920 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 13 ms 9852 KB Output is correct
3 Correct 12 ms 9920 KB Output is correct
4 Incorrect 12 ms 9920 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9720 KB Output is correct
2 Correct 13 ms 9852 KB Output is correct
3 Correct 12 ms 9920 KB Output is correct
4 Incorrect 12 ms 9920 KB Output isn't correct
5 Halted 0 ms 0 KB -