Submission #1033731

# Submission time Handle Problem Language Result Execution time Memory
1033731 2024-07-25T04:35:03 Z vjudge1 Bitaro, who Leaps through Time (JOI19_timeleap) C++17
0 / 100
8 ms 10076 KB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 2e5 + 1;
const string NAME = "city";
int n;
vector<int> adj[N];

namespace Subtask1{
    const int maxN = 21;

    int ans[maxN];
    int d[maxN][maxN], q[4 * maxN];


    void BFS(int s){
        int l = 1, r = 1;
        q[r] = s;
        d[s][s] = 0;
        while(l <= r){
            int u = q[l++];
            for(int i = 0; i < adj[u].size(); ++i){
                int v = adj[u][i];
                if(d[s][v] > d[s][u] + 1){
                    d[s][v] = d[s][u] + 1;
                    q[++r] = v;
                }
            }
        }
    }

    void main(){
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                d[i][j] = maxN;
        for(int i = 1; i <= n; ++i)
            ans[i] = 0, BFS(i);
        for(int mask = 0; mask < (1 << n); ++mask){
            vector<int> idx;
            for(int i = 1; i <= n; ++i){
                if((mask >> (i - 1)) & 1){
                    idx.pb(i);
                }
            }
            ii mm = mp(1e9, 0);
            for(int i = 1; i <= n; ++i){
                int t = 0;
                for(int j = 0; j < idx.size(); ++j)
                    t += d[i][idx[j]];
                if(t < mm.fi)
                    mm = mp(t, 1);
                else if(t == mm.fi)
                    ++mm.se;
            }
            ans[idx.size()] = max(ans[idx.size()], mm.se);
        }
        for(int i = 1; i <= n; ++i)
            cout << ans[i] << "\n";
    }
};

void inp(){
    cin >> n;
    for(int i = 1; i < n; ++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
}

void solve(){
    if(n <= 16)
        return Subtask1::main();
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

Compilation message

timeleap.cpp: In function 'void Subtask1::BFS(int)':
timeleap.cpp:28:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             for(int i = 0; i < adj[u].size(); ++i){
      |                            ~~^~~~~~~~~~~~~~~
timeleap.cpp: In function 'void Subtask1::main()':
timeleap.cpp:54:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |                 for(int j = 0; j < idx.size(); ++j)
      |                                ~~^~~~~~~~~~~~
timeleap.cpp: In function 'int main()':
timeleap.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 10076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 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 10076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -