답안 #668528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668528 2022-12-04T03:40:20 Z 4EVER Cijanobakterije (COCI21_cijanobakterije) C++11
70 / 70
41 ms 16696 KB
/******************************
*    author : @hihihihi       *
*    date : 07 / 11 / 2022    *
******************************/

#include <bits/stdc++.h>
// #pragma GCC optimize("O2")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize ("O3,unroll-loops,no-stack-protector")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// template
#define PB push_back
#define ALL(i_) i_.begin(), i_.end()
#define LOG2(x_) (31 - __builtin_clz(x_))
#define getBit(x_, i_) ((x_ >> i_) & (ll) 1)
#define rd(l_, r_) (l_ + rng() % (r_ - l_ + 1))
#define FOR(i_, a_, b_)  for(int i_ = (int) (a_); i_ <= (int) (b_); ++i_)
#define FORD(i_, a_, b_) for(int i_ = (int) (a_); i_ >= (int) (b_); --i_)
// debugger 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef DEBUG
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
typedef long long ll;
typedef long double ld;

template<class X, class Y> bool minimize(X &x, const Y &y){
    X eps = 1e-9;
    if (x > y + eps) {
        x = y;
        return 1;
    }
    return 0;
}

template<class X, class Y> bool maximize(X &x, const Y &y) {
    X eps = 1e-9;
    if (x + eps < y) {
        x = y;
        return 1;
    }
    return 0;
}

template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); }
template<class T> using heap_min = priority_queue<T, vector<T>, greater<T>>;
template<class T> using heap_max = priority_queue<T>;

const int mod = (int) 1e9 + 7;

template<class X, class Y> void Add(X &x, const Y &y){
    x += y;
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
}

const int oo = (int) 1e9 + 99;
const array<int, 2> dxy8[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1}, {1, -1}, {1, 1}, {-1, 1}, {-1, -1} };
const array<int, 2> dxy4[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };

const int maxn = (int) 1e5 + 1;
const int LOG = (int) LOG2(maxn) + 3;

void File(){
    #define TASK "CIJANOBAKTERIJE"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
}

int n, m;
vector<int> adj[maxn];

void ReadInput(){
    cin >> n >> m;
    FOR(i, 1, m){
        int u, v; cin >> u >> v;
        adj[u].PB(v);
        adj[v].PB(u);
    }
}

int cnt;
int vs[maxn], in[maxn], out[maxn];
int child[3][maxn];

void DFS_IN(int u, int par){
    vs[u] = cnt;
    child[1][u] = child[2][u] = (int) -1e7;
    for(int v : adj[u]) if(v != par){
        DFS_IN(v, u);
        maximize(in[u], in[v] + 1);
        if(in[v] + 1 > child[1][u]){
            child[2][u] = child[1][u];
            child[1][u] = in[v] + 1;
        }
        else if(in[v] + 1 > child[2][u]){
            child[2][u] = in[v] + 1;
        }
    }
}

void DFS_OUT(int u, int par){
    if(par != -1){
        out[u] = out[par] + 1;
        if(in[u] + 1 == child[1][par]){
            maximize(out[u], child[2][par] + 1);
        }
        else{
            maximize(out[u], child[1][par] + 1);
        }
    }
    for(int v : adj[u]) if(v != par) DFS_OUT(v, u);
}

int f[maxn];

void Solve(){
    memset(vs, -1, sizeof vs);
    FOR(i, 1, n) if(vs[i] == -1){
        ++cnt;
        DFS_IN(i, -1);
        DFS_OUT(i, -1);
    }
    int res = 0;
    FOR(i, 1, n) maximize(f[vs[i]], max(in[i], out[i]) + 1);
    FOR(i, 1, cnt) res += f[i];
    cout << res;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    File();
    ReadInput();
    Solve();
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}

Compilation message

Main.cpp: In function 'void File()':
Main.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4052 KB Output is correct
2 Correct 12 ms 4948 KB Output is correct
3 Correct 17 ms 6012 KB Output is correct
4 Correct 26 ms 6960 KB Output is correct
5 Correct 35 ms 7960 KB Output is correct
6 Correct 41 ms 8948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 16696 KB Output is correct
2 Correct 4 ms 3796 KB Output is correct
3 Correct 6 ms 4620 KB Output is correct
4 Correct 9 ms 5396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3064 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3064 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 4 ms 3796 KB Output is correct
6 Correct 8 ms 4620 KB Output is correct
7 Correct 10 ms 5568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3076 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3068 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4052 KB Output is correct
2 Correct 12 ms 4948 KB Output is correct
3 Correct 17 ms 6012 KB Output is correct
4 Correct 26 ms 6960 KB Output is correct
5 Correct 35 ms 7960 KB Output is correct
6 Correct 41 ms 8948 KB Output is correct
7 Correct 34 ms 16696 KB Output is correct
8 Correct 4 ms 3796 KB Output is correct
9 Correct 6 ms 4620 KB Output is correct
10 Correct 9 ms 5396 KB Output is correct
11 Correct 2 ms 3064 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3064 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 4 ms 3796 KB Output is correct
16 Correct 8 ms 4620 KB Output is correct
17 Correct 10 ms 5568 KB Output is correct
18 Correct 2 ms 3076 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 2 ms 3028 KB Output is correct
26 Correct 2 ms 3068 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3072 KB Output is correct
29 Correct 40 ms 8916 KB Output is correct
30 Correct 9 ms 5972 KB Output is correct
31 Correct 25 ms 8524 KB Output is correct
32 Correct 18 ms 6808 KB Output is correct
33 Correct 32 ms 8800 KB Output is correct
34 Correct 29 ms 7356 KB Output is correct
35 Correct 34 ms 8600 KB Output is correct
36 Correct 30 ms 7788 KB Output is correct
37 Correct 31 ms 8832 KB Output is correct
38 Correct 37 ms 8272 KB Output is correct
39 Correct 29 ms 8644 KB Output is correct