Submission #959605

# Submission time Handle Problem Language Result Execution time Memory
959605 2024-04-08T13:40:53 Z Cookie Island (NOI18_island) C++14
100 / 100
46 ms 6616 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 998244353, pr = 31;
const int mxn = 2e5 + 5, mxq = 1e5 + 5, sq = 300, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e16 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
// <3;
int n, m;
int cnt[mxn + 1], mn[mxn + 1], cntp[mxn + 1], deg[mxn + 1];
void solve(){
    cin >> n >> m;
    if(n == 2 && m == 0){
        cout << 1 << " " << 1;
        return;
    }
    for(int i = 2; i * i <= mxn; i++){
        if(!mn[i]){
            for(int j = i * i; j <= mxn; j += i){
                if(!mn[j])mn[j] = i;
            }
        }
    }
    for(int i = 2; i <= mxn; i++){
        if(!mn[i])mn[i] = i;
    }
    for(int i = 0; i < n + m - 1; i++){
        int u, v; cin >> u >> v;
        deg[u]++; deg[v]++;
    }
    for(int i = n + 1; i <= n + m - 1; i++)cnt[deg[i] - 1]++;
    cnt[deg[n + m] - 1]++;
    for(int i = n + m - 1; i >= 2; i--){
        cnt[i] += cnt[i + 1];
        int x = i;
        while(x != 1){
            int cr = mn[x], cntt = 0;
            while(x % cr == 0){
                x /= cr; cntt++;
            }
            cntp[cr] += cntt * cnt[i];
        }
    }
    vt<pll>pr;
    for(int i = 2; i <= n + m; i++){
        if(cntp[i]){
            pr.pb(mpp(i, cntp[i]));
        }
    }
    for(int i =0 ; i < sz(pr); i++){
        cout << pr[i].fi << " " << pr[i].se;
        if(i != sz(pr) - 1)cout << "\n";
    }
}


signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("netw.inp", "r", stdin);
    //freopen("netw.out", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();

    }
    return(0);
}
/*
1
5 7 2
1 1 1
3 1 2
2 2 3
4 2 4
2 4 2
1 5 5
3 5 2
5 3
2 7
3 3 1
1 1 1
1 2 2
1 3 3
3 1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 38 ms 6108 KB Output is correct
4 Correct 46 ms 6604 KB Output is correct
5 Correct 9 ms 2396 KB Output is correct
6 Correct 42 ms 6616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1112 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 2 ms 1116 KB Output is correct
6 Correct 2 ms 1112 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 38 ms 6108 KB Output is correct
4 Correct 46 ms 6604 KB Output is correct
5 Correct 9 ms 2396 KB Output is correct
6 Correct 42 ms 6616 KB Output is correct
7 Correct 2 ms 1116 KB Output is correct
8 Correct 2 ms 1116 KB Output is correct
9 Correct 2 ms 1112 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 2 ms 1116 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 2 ms 1112 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 1116 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 5 ms 1368 KB Output is correct
27 Correct 41 ms 6448 KB Output is correct
28 Correct 42 ms 6616 KB Output is correct
29 Correct 25 ms 4184 KB Output is correct
30 Correct 39 ms 5968 KB Output is correct
31 Correct 10 ms 1880 KB Output is correct
32 Correct 6 ms 1628 KB Output is correct
33 Correct 37 ms 5792 KB Output is correct
34 Correct 35 ms 5456 KB Output is correct
35 Correct 40 ms 5968 KB Output is correct
36 Correct 39 ms 5972 KB Output is correct
37 Correct 1 ms 344 KB Output is correct