Submission #1129276

#TimeUsernameProblemLanguageResultExecution timeMemory
1129276jackofall718Island (NOI18_island)C++20
0 / 100
1 ms448 KiB
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define vn vector<ll>
using namespace std;

const int MAX_N = 1e9 + 7;
#define pii pair<ll,ll>
const ll INF = 0x3f3f3f3f3f3f3f3f;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, m;
    cin >> n >> m;            // N towns, M junctions

    vn weights(m + 1, 0);     // 1) Allocates array of length (m+1), all zero
    ll junc = 0;

    // 2) Read (n + m - 1) edges
    for (int i = 0; i < n + m - 1; i++) {
        ll u, v;
        cin >> u >> v;

        // If both endpoints > n, increment 'junc'
        // (apparently counting edges that connect junctions?)
        if (u > n && v > n) {
            junc++;
        } 
        else {
            // Take the bigger endpoint and increment weights[temp]
            ll temp = max(u, v);
            weights[temp] += 1;
        }
    }

    // 3) Some loop over i=1..m
    for (int i = 1; i <= m; i++) {
        // Attempt to set:
        //   weights[i] = max(2LL, weights[i-1] * weights[i-2]);
        //
        // But notice that for i=1, i-2 = -1 => out of bounds!
        // Also i-1=0 => that is valid, but i-2=-1 is not.
        weights[i] = max(2LL, weights[i-1] * weights[i-2]);
    }

    // 4) Multiply all weights[i] into 'ans'
    ll ans = 1;
    for (int i = 1; i <= m; i++) {
        ans *= weights[i];
    }

    // Print 'ans 1'
    cout << ans << " " << 1 << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...