답안 #236003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236003 2020-05-30T18:16:29 Z ant101 Uzastopni (COCI15_uzastopni) C++14
0 / 160
137 ms 65540 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

typedef long long ll;


ll add(ll a, ll b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}

ll mul(ll a, ll b) {
    return (a * b)%MOD;
}

void add_self(ll& a, ll b) {
    a = add(a, b);
}
void sub_self(ll& a, ll b) {
    a = sub(a, b);
}
void mul_self(ll& a, ll b) {
    a = mul(a, b);
}


const ll MAXN = 10;

ll N;
ll V[MAXN];
vector<ll> adj[MAXN];
vector<ll> lrange[MAXN][101];
vector<ll> rrange[MAXN][101];
vector<ll> st[MAXN];
vector<ll> en[MAXN];


void dfsleft(ll node, ll u) {
    st[node].push_back(u);
    if (u <= 1) {
        return;
    }
    for (auto v : lrange[node][u-1]) {
        dfsleft(node, v);
    }
}

void dfsright(ll node, ll u) {
    en[node].push_back(u);
    if (u >= 100) {
        return;
    }
    for (auto v : rrange[node][u+1]) {
        dfsright(node, v);
    }
}


void f(ll u, ll p) {
    for (ll i = 0; i<adj[u].size(); i++) {
        ll v = adj[u][i];
        if (v == p) {
            continue;
        }
        f(v, u);
        for (ll j = 0; j<st[v].size(); j++) {
            for (ll k = 0; k<en[v].size(); k++) {
                ll first = st[v][j], second = en[v][k];
                if (first > second) {
                    continue;
                }
                lrange[u][second].push_back(first);
                rrange[u][first].push_back(second);
            }
        }
    }
    dfsleft(u, V[u]);
    dfsright(u, V[u]);
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (ll i = 1; i<=N; i++) {
        cin >> V[i];
    }
    for (ll i = 0; i<N-1; i++) {
        ll a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        
    }
    f(1, -1);
    cout << st[1].size()*en[1].size() << "\n";
    return 0;
}




Compilation message

uzastopni.cpp: In function 'void f(ll, ll)':
uzastopni.cpp:94:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll i = 0; i<adj[u].size(); i++) {
                    ~^~~~~~~~~~~~~~
uzastopni.cpp:100:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (ll j = 0; j<st[v].size(); j++) {
                        ~^~~~~~~~~~~~~
uzastopni.cpp:101:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (ll k = 0; k<en[v].size(); k++) {
                            ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Incorrect 4 ms 384 KB Output isn't correct
3 Runtime error 137 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Runtime error 7 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Incorrect 5 ms 384 KB Output isn't correct
9 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 8 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 48 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 45 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 7 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Incorrect 4 ms 384 KB Output isn't correct
18 Incorrect 5 ms 384 KB Output isn't correct
19 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)