#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "meetings.h"
int M[2000][2000];
bitset<2000> P[2000],C[2000];
int lca(int v,int w) {
//cout<<"lca "<<v<<","<<w<<endl;
if ((v == 0) || (w == 0)) return 0;
else if (v == w) return v;
if (M[v][w] != -1) return M[v][w];
else if (P[w][v] || C[v][w]) return v;
else if (P[v][w] || C[w][v]) return w;
else {
M[v][w] = M[w][v] = Query(0,v,w);
C[M[v][w]][v] = C[M[w][v]][w] = 1;
P[v][M[v][w]] = P[w][M[v][w]] = 1;
if (M[v][w] == v) P[w] |= P[v],C[v] |= C[w];
else if (M[v][w] == w) P[v] |= P[w],C[w] |= C[v];
else C[M[v][w]] |= C[v] | C[w];
return M[v][w];
}
}/*
int solve(vi v,int r,int N) {
if (v.size() <= 1) return 0;
int i,j;
vector<vi> sub;
vi child;
for (i = 0; i < v.size(); i++) {
int u = v[i];
if (u == r) continue;
if (sub.empty()) sub.pb(vi()),sub[0].pb(u),child.pb(u);
else {
int k,c;
vpii order;
for (j = 0; j < sub.size(); j++) order.pb(mp(sub[j].size(),j));
sort(order.begin(),order.end(),greater<pii>());
for (j = 0; j < sub.size(); j++) {
k = order[j].second;
if ((c=lca(child[k],u,N)) != r) break;
}
if (j == sub.size()) sub.pb(vi()),sub.back().pb(u),child.pb(u);
else sub[k].pb(u),child[k] = c;
}
}
for (i = 0; i < sub.size(); i++) {
if (r < child[i]) Bridge(r,child[i]);
else Bridge(child[i],r);
solve(sub[i],child[i],N);
}
return 0;
}*/
vi adjList[2000];
int done[2000];
int parent[2000],size[2000],heavy[2000];
int chain[2000],head[2000],csize[2000],tail[2000],c = 0;
int doDFS(int u,int p) {
int i;
parent[u] = p,size[u] = 1,heavy[u] = -1;
//if (p != -1) cout<<"EDGE "<<u<<" "<<p<<endl;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v != p) {
size[u] += doDFS(v,u);
if ((heavy[u] == -1) || (size[v] > size[heavy[u]])) heavy[u] = v;
}
}
return size[u];
}
int doHLD(int u,int p) {
int i;
chain[u] = c,tail[c] = u;
if (csize[c] == 0) head[c] = u;
csize[c]++;
if (heavy[u] != -1) doHLD(heavy[u],u);
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if ((v != p) && (v != heavy[u])) c++,doHLD(v,u);
}
return 0;
}
int add(int u,int s) {
int i;
//cout<<"add "<<u<<" "<<s<<endl;
if (heavy[s] == -1) {
adjList[s].pb(u);
adjList[u].pb(s);
return 0;
}
int x = tail[chain[s]];
int v = lca(x,u);
if (!done[v]) {
vi path;
int t = s;
while (t != -1) path.pb(t),t = heavy[t];
int l = 1,r = path.size()-1;
while (l < r) {
int m = (l+r) / 2;
if (lca(path[m],u) == v) r = m;
else l = m+1;
}
//cout<<path[l-1]<<","<<path[l]<<endl;
adjList[path[l-1]].erase(find(adjList[path[l-1]].begin(),adjList[path[l-1]].end(),path[l]));
adjList[path[l]].erase(find(adjList[path[l]].begin(),adjList[path[l]].end(),path[l-1]));
adjList[path[l]].pb(v),adjList[v].pb(path[l]);
adjList[path[l-1]].pb(v),adjList[v].pb(path[l-1]);
if (u != v) adjList[u].pb(v),adjList[v].pb(u);
done[v] = 1;
return 0;
}
else if (v == s) {
for (i = 0; i < adjList[s].size(); i++) {
int t = adjList[s][i];
if ((t == parent[s]) || (t == heavy[s])) continue;
if (lca(tail[chain[t]],u) != s) {
if (lca(t,u) != t) {
v = lca(t,u);
adjList[s].erase(find(adjList[s].begin(),adjList[s].end(),t));
adjList[t].erase(find(adjList[t].begin(),adjList[t].end(),s));
adjList[t].pb(v),adjList[v].pb(s);
adjList[s].pb(v),adjList[v].pb(t);
if (u != v) adjList[u].pb(v),adjList[v].pb(u);
done[v] = 1;
return 0;
}
else add(u,t);
return 0;
}
}
adjList[s].pb(u);
adjList[u].pb(s);
return 0;
}
else {
vi path;
int t = s;
while (t != -1) path.pb(t),t = heavy[t];
int l = 1,r = path.size()-1;
while (l < r) {
int m = (l+r) / 2;
if (lca(path[m],u) == v) r = m;
else l = m+1;
}
add(u,path[l]);
return 0;
}
}
void Solve(int N) {
int i;
for (i = 0; i < N; i++) fill(M[i],M[i]+N,-1);
done[0] = 1;
for (i = 1; i < N; i++) {
if (!done[i]) {
doDFS(0,-1),c = 0,doHLD(0,-1),c++;
//cout<<"here"<<endl;
add(i,0);
done[i] = 1;
//cout<<"here"<<endl;
//cout<<"fin "<<i<<endl;
//for(int j=0;j<N;j++){
// for (int k =0;k<adjList[j].size();k++)cout<<j<<" "<<adjList[j][k]<<endl;
//}
}
}
doDFS(0,-1);
for (i = 1; i < N; i++) {
if (parent[i] < i) Bridge(parent[i],i);
else Bridge(i,parent[i]);
}
}
Compilation message
meetings.cpp: In function 'int doDFS(int, int)':
meetings.cpp:115:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
meetings.cpp: In function 'int doHLD(int, int)':
meetings.cpp:130:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
meetings.cpp: In function 'int add(int, int)':
meetings.cpp:166:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[s].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
2 ms |
768 KB |
Output is correct |
20 |
Correct |
2 ms |
688 KB |
Output is correct |
21 |
Correct |
2 ms |
768 KB |
Output is correct |
22 |
Correct |
2 ms |
640 KB |
Output is correct |
23 |
Correct |
2 ms |
768 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
2 ms |
768 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
2 ms |
768 KB |
Output is correct |
20 |
Correct |
2 ms |
688 KB |
Output is correct |
21 |
Correct |
2 ms |
768 KB |
Output is correct |
22 |
Correct |
2 ms |
640 KB |
Output is correct |
23 |
Correct |
2 ms |
768 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
640 KB |
Output is correct |
27 |
Correct |
10 ms |
2148 KB |
Output is correct |
28 |
Correct |
9 ms |
2176 KB |
Output is correct |
29 |
Correct |
9 ms |
2176 KB |
Output is correct |
30 |
Correct |
10 ms |
2176 KB |
Output is correct |
31 |
Correct |
9 ms |
2176 KB |
Output is correct |
32 |
Correct |
11 ms |
2176 KB |
Output is correct |
33 |
Correct |
15 ms |
2176 KB |
Output is correct |
34 |
Correct |
16 ms |
2176 KB |
Output is correct |
35 |
Correct |
17 ms |
2056 KB |
Output is correct |
36 |
Correct |
10 ms |
2176 KB |
Output is correct |
37 |
Correct |
13 ms |
2096 KB |
Output is correct |
38 |
Correct |
14 ms |
2252 KB |
Output is correct |
39 |
Correct |
6 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
973 ms |
17448 KB |
Output is correct |
2 |
Correct |
1034 ms |
17340 KB |
Output is correct |
3 |
Correct |
898 ms |
17392 KB |
Output is correct |
4 |
Correct |
944 ms |
17432 KB |
Output is correct |
5 |
Correct |
511 ms |
17352 KB |
Output is correct |
6 |
Correct |
545 ms |
17344 KB |
Output is correct |
7 |
Correct |
620 ms |
17308 KB |
Output is correct |
8 |
Correct |
764 ms |
17288 KB |
Output is correct |
9 |
Correct |
778 ms |
17292 KB |
Output is correct |
10 |
Correct |
815 ms |
17216 KB |
Output is correct |
11 |
Correct |
813 ms |
17292 KB |
Output is correct |
12 |
Correct |
861 ms |
17512 KB |
Output is correct |
13 |
Correct |
650 ms |
17492 KB |
Output is correct |
14 |
Correct |
737 ms |
17356 KB |
Output is correct |
15 |
Correct |
753 ms |
17268 KB |
Output is correct |
16 |
Correct |
785 ms |
17332 KB |
Output is correct |
17 |
Correct |
1061 ms |
16936 KB |
Output is correct |
18 |
Correct |
619 ms |
17404 KB |
Output is correct |
19 |
Correct |
600 ms |
17600 KB |
Output is correct |
20 |
Correct |
823 ms |
17696 KB |
Output is correct |
21 |
Correct |
801 ms |
17516 KB |
Output is correct |
22 |
Correct |
823 ms |
17528 KB |
Output is correct |
23 |
Correct |
788 ms |
17464 KB |
Output is correct |
24 |
Correct |
783 ms |
17468 KB |
Output is correct |
25 |
Correct |
753 ms |
17452 KB |
Output is correct |
26 |
Correct |
736 ms |
17528 KB |
Output is correct |
27 |
Correct |
756 ms |
17680 KB |
Output is correct |
28 |
Correct |
919 ms |
17528 KB |
Output is correct |
29 |
Correct |
954 ms |
17400 KB |
Output is correct |
30 |
Correct |
885 ms |
17400 KB |
Output is correct |
31 |
Correct |
864 ms |
17368 KB |
Output is correct |
32 |
Correct |
1211 ms |
17784 KB |
Output is correct |
33 |
Correct |
175 ms |
17528 KB |
Output is correct |
34 |
Correct |
10 ms |
2176 KB |
Output is correct |
35 |
Correct |
10 ms |
2176 KB |
Output is correct |
36 |
Correct |
10 ms |
2168 KB |
Output is correct |
37 |
Correct |
10 ms |
2176 KB |
Output is correct |
38 |
Correct |
9 ms |
2176 KB |
Output is correct |
39 |
Correct |
12 ms |
2176 KB |
Output is correct |
40 |
Correct |
16 ms |
2176 KB |
Output is correct |
41 |
Correct |
18 ms |
2176 KB |
Output is correct |
42 |
Correct |
17 ms |
2168 KB |
Output is correct |
43 |
Correct |
10 ms |
2176 KB |
Output is correct |
44 |
Correct |
13 ms |
2176 KB |
Output is correct |
45 |
Correct |
14 ms |
2176 KB |
Output is correct |
46 |
Correct |
6 ms |
2096 KB |
Output is correct |
47 |
Correct |
2 ms |
768 KB |
Output is correct |
48 |
Correct |
2 ms |
768 KB |
Output is correct |
49 |
Correct |
2 ms |
768 KB |
Output is correct |
50 |
Correct |
2 ms |
768 KB |
Output is correct |
51 |
Correct |
2 ms |
768 KB |
Output is correct |
52 |
Correct |
2 ms |
640 KB |
Output is correct |
53 |
Correct |
2 ms |
640 KB |
Output is correct |
54 |
Correct |
2 ms |
640 KB |
Output is correct |
55 |
Correct |
2 ms |
768 KB |
Output is correct |
56 |
Correct |
2 ms |
768 KB |
Output is correct |
57 |
Correct |
2 ms |
640 KB |
Output is correct |
58 |
Correct |
2 ms |
640 KB |
Output is correct |
59 |
Correct |
2 ms |
640 KB |
Output is correct |
60 |
Correct |
2 ms |
384 KB |
Output is correct |
61 |
Correct |
2 ms |
384 KB |
Output is correct |
62 |
Correct |
2 ms |
512 KB |
Output is correct |
63 |
Correct |
2 ms |
384 KB |
Output is correct |
64 |
Correct |
2 ms |
384 KB |
Output is correct |
65 |
Correct |
2 ms |
384 KB |
Output is correct |
66 |
Correct |
2 ms |
384 KB |
Output is correct |
67 |
Correct |
1 ms |
532 KB |
Output is correct |
68 |
Correct |
2 ms |
384 KB |
Output is correct |
69 |
Correct |
2 ms |
512 KB |
Output is correct |
70 |
Correct |
2 ms |
384 KB |
Output is correct |
71 |
Correct |
2 ms |
512 KB |
Output is correct |
72 |
Correct |
2 ms |
384 KB |
Output is correct |