Submission #1033733

# Submission time Handle Problem Language Result Execution time Memory
1033733 2024-07-25T04:35:54 Z vjudge1 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
0 / 100
6 ms 10076 KB
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n;
vector <int> adj[N];
namespace sub1{
    int cnt = 0;
    int ans[22], child[22], dis[22];
    int mindis, tmp;
    void pre(int u, int p){
        dis[u] = 0;
        for (int v : adj[u]){
            if (v == p) continue;
            pre(v, u);
            child[u] += child[v];
            dis[u] += dis[v] + child[v];
        }
        return;
    }
    void dfs(int u, int p){
        if (dis[u] == mindis){
            ++tmp;
        }
        if (dis[u] < mindis){
            tmp = 1;
            mindis = dis[u];
        }
        for (int v : adj[u]){
            if (v == p) continue;
            dis[v] = dis[u] - child[v] + cnt - child[v];
            dfs(v, u);
        }
    }
    void solve(){
        for (int mask = 1;mask < (1 << n);++mask){
            cnt = 0;
            tmp = 0;
            mindis = oo;
            for (int i = 1;i <= n;++i){
                child[i] = 0;
                if ((1 << (i - 1)) & mask){
                    child[i] = 1;
                    ++cnt;
                }
            }
            pre(1, 0);
            dfs(1, 0);
            ans[cnt] = max(ans[cnt], tmp);
        }
        for (int i = 1;i <= n;i++){
            cout << ans[i] <<"\n";
        }
    }
};
void solve(){
    cin >> n;
    for (int i = 1;i < n;++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if (n <= 20){
        sub1::solve();
        return;
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    if (fopen("City.inp", "r")){
        freopen("City.inp", "r", stdin);
        freopen("City.out", "w", stdout);
    }
//    int t;
//    cin >> t;
//    while(t--){
    solve();
//    }
    return 0;
}

Compilation message

timeleap.cpp: In function 'int main()':
timeleap.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen("City.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen("City.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 10072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 10072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -