답안 #40353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40353 2018-01-31T09:22:46 Z krauch 동기화 (JOI13_synchronization) C++14
0 / 100
161 ms 25724 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > PII;

#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)

const ll ool = 1e18 + 9;
const int N = 3e5 + 3, oo = 1e9 + 9;

int n, m, Q;
vector < int > vec[N];
vector < PII > g[N];

int dfs(int v, int par, int X) {
    int res = 1;
    for (auto it : g[v]) {
        int to = it.F;
        if (to == par) continue;
        int pos = lower_bound(all(vec[it.S]), X) - vec[it.S].begin() - 1;
        if (pos < 0) continue;
        res += dfs(to, v, vec[it.S][pos]);
    }
    return res;
}

int main() {

    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #endif

    scanf("%d%d%d", &n, &m, &Q);
    forn(i, 1, n - 1) {
        int x, y;
        scanf("%d%d", &x, &y);
        g[x].eb(y, i);
        g[y].eb(x, i);
    }

    forn(i, 1, m) {
        int x;
        scanf("%d", &x);
        vec[x].eb(i);
    }

    forn(i, 1, Q) {
        int x;
        scanf("%d", &x);
        cout << dfs(x, 0, m + 1) << "\n";
    }

    return 0;
}

Compilation message

synchronization.cpp: In function 'int main()':
synchronization.cpp:42:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &Q);
                                ^
synchronization.cpp:45:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
                              ^
synchronization.cpp:52:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
                        ^
synchronization.cpp:58:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14408 KB Output is correct
2 Correct 13 ms 14564 KB Output is correct
3 Incorrect 15 ms 14640 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 83 ms 23720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 161 ms 25724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 25724 KB Output is correct
2 Correct 12 ms 25724 KB Output is correct
3 Incorrect 12 ms 25724 KB Output isn't correct
4 Halted 0 ms 0 KB -