답안 #704021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704021 2023-03-01T11:33:31 Z Username4132 Logičari (COCI21_logicari) C++14
110 / 110
152 ms 19504 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back

const int MAXN=100010, INF=100000000;
int n, x, y, res[MAXN][2][2];
bool vis[MAXN], gcov, gblue;
vector<int> g[MAXN];

inline int wrap(int v, bool blue, bool cover){
    if(v!=y) return res[v][blue][cover];
    else if((gcov^blue) || (gblue && cover)) return -INF;
    else return res[v][blue][cover||gblue];
}

void cyc(int v, int p){
    vis[v]=true;
    for(auto to:g[v]){
        if(to==p) continue;
        if(vis[to]) x=v, y=to;
        else cyc(to, v);
    }
}

void dfs(int v, int p){
    ll ybl=0, nbl=0;
    for(auto to:g[v]){
        if(to==p) continue;
        dfs(to, v);
        ybl+=wrap(to, 0, 1);
        nbl+=wrap(to, 0, 0);
    }
    res[v][0][1]=max(nbl, (ll)(-INF));
    res[v][1][1]=max(ybl+1, (ll)(-INF));
    ll yy=-INF, nn=-INF;
    for(auto to:g[v]){
        if(to==p) continue;
        ll yyy=ybl-wrap(to, 0, 1)+wrap(to, 1, 1);
        ll nnn=nbl-wrap(to, 0, 0)+wrap(to, 1, 0);
        yy = max(yy, yyy), nn = max(nn, nnn);
    }
    res[v][0][0]=max(nn, (ll)(-INF));
    res[v][1][0]=max(yy+1, (ll)(-INF));
}

int main(){
    scanf("%d", &n);
    forn(i, n){
        int a, b; scanf("%d %d", &a, &b);
        --a, --b;
        g[a].PB(b), g[b].PB(a);
    }
    cyc(0, 0);
    g[x].erase(find(g[x].begin(), g[x].end(), y));
    g[y].erase(find(g[y].begin(), g[y].end(), x));

    int mx=-1;
    forn(i, 4){
        gblue = i>>1, gcov = i&1;
        dfs(x, x);
        mx = max(mx, res[x][gblue][gcov]);
    }

    printf("%d\n", mx);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:53:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         int a, b; scanf("%d %d", &a, &b);
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 136 ms 19388 KB Output is correct
6 Correct 115 ms 19344 KB Output is correct
7 Correct 152 ms 19400 KB Output is correct
8 Correct 139 ms 19396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2572 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2660 KB Output is correct
6 Correct 2 ms 2556 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2656 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2572 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2660 KB Output is correct
6 Correct 2 ms 2556 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2656 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2660 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 136 ms 19388 KB Output is correct
6 Correct 115 ms 19344 KB Output is correct
7 Correct 152 ms 19400 KB Output is correct
8 Correct 139 ms 19396 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2572 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2660 KB Output is correct
14 Correct 2 ms 2556 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 3 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2660 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2772 KB Output is correct
32 Correct 2 ms 2772 KB Output is correct
33 Correct 79 ms 7996 KB Output is correct
34 Correct 67 ms 7992 KB Output is correct
35 Correct 91 ms 7932 KB Output is correct
36 Correct 79 ms 7988 KB Output is correct
37 Correct 14 ms 3964 KB Output is correct
38 Correct 59 ms 8024 KB Output is correct
39 Correct 6 ms 3096 KB Output is correct
40 Correct 78 ms 7924 KB Output is correct
41 Correct 66 ms 8784 KB Output is correct
42 Correct 68 ms 8948 KB Output is correct
43 Correct 121 ms 19504 KB Output is correct
44 Correct 79 ms 14144 KB Output is correct