AtCoder Petrozavodsk Contest 001

Submission #2061424

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll solve(int N) {
    return -1LL;
}

int main() {
    int N; cin >> N;
    vector<vector<int>> ne(N); // 隣、x
    rep(i, N-1) {
        int xi, yi; cin >> xi >> yi;
        ne[xi].pb(yi);
        ne[yi].pb(xi);
    }
    vector<int> br(N, 0);
    rep(i, N) br[i] += ne[i].size();
    int max_at = -1, max_br = -1;
    rep(i, N) {
        if (br[i] > max_br) { max_at = i; max_br = br[i]; }
    }

    queue<int> q;
    vector<int> ord;
    q.push(max_at);
    vector<int> parent(N, -1), children(N, 0);
    vector<bool> visited(N, false);
    while(!q.empty()) {
        int u = q.front(); q.pop();
        visited[u] = true;
        ord.pb(u);
        for (int v : ne[u]) {
            if (visited[v]) continue;
            q.push(v);
            parent[v] = u;
            ++children[u];
        }
    }
#ifdef DEBUG
    cout << "ord:" << ord << endl;
    cout << "parent:" << parent << endl;
    cout << "children:" << children << endl;
#endif

    vector<int> val(N, 0);
    vector<vector<ii>> escal(N);
    rep(u, N) if (children[u] == 0) { val[u] = 1; escal[u].pb(ii(1, 0)); }
    // unerasable

    for (int i=N-1; i>=0; --i) {
        int v = ord[i];
        val[v] = 0;
        int l = 0;
        for (auto p : escal[v]) {
            val[v] += p.first;
            if (p.second == 1) l = 1;
        }
        if (children[v] >= 2) {
            for (ii p : escal[v]) {
                if (p.first == 1 && p.second == 0) {
                    val[v]--; break;
                }
            }
        }

        int u = parent[v];
        if (u != -1) {
            escal[u].pb(ii(val[v], (children[v]>=2)?1:l));
        }
    }
#ifdef DEBUG
    cout << endl;
    cout << "escal:" << escal << endl;
    cout << "val:" << val << endl;
#endif
    cout << val[max_at] << endl;

    return 0;
}

Submission

Task問題 E - Antennas on Tree
User nameユーザ名 naoya_t
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 900
Source lengthソースコード長 2951 Byte
File nameファイル名
Exec time実行時間 96 ms
Memory usageメモリ使用量 14916 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
All 900 / 900 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,1_13.txt,1_14.txt,1_15.txt,1_16.txt,1_17.txt,1_18.txt,1_19.txt,1_20.txt,1_21.txt,1_22.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 91 ms 13176 KB
1_07.txt AC 82 ms 14708 KB
1_08.txt AC 93 ms 13176 KB
1_09.txt AC 82 ms 14708 KB
1_10.txt AC 90 ms 12924 KB
1_11.txt AC 91 ms 13044 KB
1_12.txt AC 91 ms 12796 KB
1_13.txt AC 94 ms 13300 KB
1_14.txt AC 96 ms 13176 KB
1_15.txt AC 93 ms 13328 KB
1_16.txt AC 95 ms 13476 KB
1_17.txt AC 96 ms 13760 KB
1_18.txt AC 91 ms 14200 KB
1_19.txt AC 86 ms 14620 KB
1_20.txt AC 86 ms 14584 KB
1_21.txt AC 87 ms 14712 KB
1_22.txt AC 83 ms 14916 KB