Submission #978713

# Submission time Handle Problem Language Result Execution time Memory
978713 2024-05-09T14:26:11 Z happy_node Meetings (JOI19_meetings) C++17
29 / 100
1490 ms 1108 KB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;

const int MX=2005;

set<pair<int,int>> edges;

bool used[MX], vis[MX];
int sz[MX];
int N;

vector<int> adj[MX];

int getSize(int v, int p) {
        sz[v]=1;
        for(auto u:adj[v]) {
                if(u!=p && !used[u]) {
                        sz[v]+=getSize(u,v);
                }
        }
        return sz[v];
}

int getCen(int v, int p, int s) {
        for(auto u:adj[v]) {
                if(u!=p && 2*sz[u]>s && !used[u]) {
                        return getCen(u,v,s);
                }
        }
        return v;
}

int que(int u, int v, int w) {
        // cout<<"ask "<<u<<" "<<v<<" "<<w<<endl;
        // we can memo here
        return Query(u,v,w);
}

void cdc(int v, int x) {
        // cout<<"at node : "<<v<<endl;

        int s=getSize(v,v);
        // cout<<"size : "<<s<<endl;
        int cen=getCen(v,v,s);
        getSize(cen,cen);
        used[cen]=true;

        // cout<<"at cen : "<<cen<<endl;

        bool fnd=0;

        for(auto u:adj[cen]) {
                if(used[u]) continue;
                if(que(cen,u,x)!=cen) {
                        fnd=1;

                        int k=que(cen,u,x);

                        if(k==cen) {
                                assert(false);
                        } else if(k==u) {
                                if(sz[u]>1) cdc(u,x);
                                else {
                                        vis[x]=true;
                                        edges.insert({min(u,x),max(u,x)});
                                }
                        } else if(k==x) {
                                vis[x]=true;
                                edges.erase({min(u,cen),max(u,cen)});
                                edges.insert({min(cen,x),max(cen,x)});
                                edges.insert({min(u,x),max(u,x)});
                        } else {
                                vis[x]=true;
                                vis[k]=true;
                                edges.erase({min(u,cen),max(u,cen)});
                                edges.insert({min(cen,k),max(cen,k)});
                                edges.insert({min(u,k),max(u,k)});
                                edges.insert({min(x,k),max(x,k)});
                        }

                        break;
                }
        }

        if(!fnd) {
                vis[x]=true;
                edges.insert({min(cen,x),max(cen,x)});
        }
}

void prep() {
        for(int i=0;i<N;i++) {
                used[i]=false;
                adj[i].clear();
        }
        for(auto [u,v]:edges) {
                adj[u].push_back(v);
                adj[v].push_back(u);
        }
}

void Solve(int _N) {
        N=_N;
                        
        vis[0]=true;

        for(int i=1;i<N;i++) {
                if(vis[i]) continue;
                // cout<<"try : "<<i<<endl;
                // for(auto [u,v]:edges) {
                //         cout<<u<<" "<<v<<endl;
                // } 
                prep();
                cdc(0,i);
        }
        
        for(auto [u,v]:edges) {
                if(u>v) swap(u,v);
                Bridge(u,v);
        }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 9 ms 344 KB Output is correct
28 Correct 14 ms 600 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 8 ms 600 KB Output is correct
31 Correct 10 ms 600 KB Output is correct
32 Correct 7 ms 600 KB Output is correct
33 Correct 9 ms 600 KB Output is correct
34 Correct 11 ms 600 KB Output is correct
35 Correct 15 ms 580 KB Output is correct
36 Correct 8 ms 600 KB Output is correct
37 Correct 11 ms 600 KB Output is correct
38 Correct 15 ms 600 KB Output is correct
39 Correct 13 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 852 KB Output is correct
2 Correct 825 ms 948 KB Output is correct
3 Correct 825 ms 852 KB Output is correct
4 Correct 797 ms 984 KB Output is correct
5 Correct 581 ms 1004 KB Output is correct
6 Correct 463 ms 1080 KB Output is correct
7 Correct 638 ms 724 KB Output is correct
8 Correct 763 ms 856 KB Output is correct
9 Correct 713 ms 1016 KB Output is correct
10 Correct 692 ms 1108 KB Output is correct
11 Correct 815 ms 1096 KB Output is correct
12 Correct 825 ms 888 KB Output is correct
13 Correct 760 ms 992 KB Output is correct
14 Correct 1465 ms 1088 KB Output is correct
15 Correct 1454 ms 1060 KB Output is correct
16 Correct 1490 ms 780 KB Output is correct
17 Correct 608 ms 852 KB Output is correct
18 Incorrect 1256 ms 1036 KB Wrong Answer [2]
19 Halted 0 ms 0 KB -