# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
59187 |
2018-07-21T01:02:34 Z |
duality |
Simurgh (IOI17_simurgh) |
C++11 |
|
210 ms |
11256 KB |
#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 "simurgh.h"
int label[500][500],know[500][500];
vi adjList[500];
int parent[500],disc[500],low[500],lowlabel[500];
int com[500],first[500];
int num = 0,bcc = 0;
vi S,tree;
int doDFS(int u,int p) {
int i;
parent[u] = p,disc[u] = low[u] = num++;
S.pb(u);
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (disc[v] == -1) {
tree.pb(label[u][v]),doDFS(v,u);
if (low[v] < low[u]) low[u] = low[v],lowlabel[u] = lowlabel[v];
if (low[v] > disc[u]) {
while (1) {
int w = S.back();
S.pop_back();
com[w] = bcc;
if (w == v) break;
}
bcc++;
}
}
else if ((v != p) && (disc[v] < low[u])) low[u] = disc[v],lowlabel[u] = label[u][v];
}
return 0;
}
int s[500],r[500];
vpii adjList2[125000];
int royal[125000];
int doDFS2(int u,int rr) {
if (royal[u] != -1) return 0;
int i;
royal[u] = rr;
for (i = 0; i < adjList2[u].size(); i++) doDFS2(adjList2[u][i].first,rr+adjList2[u][i].second);
return 0;
}
int ds[500];
int find(int n) {
if (ds[n] != n) ds[n] = find(ds[n]);
return ds[n];
}
int query(vi forest,vi &u,vi &v,int n) {
int i;
for (i = 0; i < n; i++) ds[i] = i;
for (i = 0; i < forest.size(); i++) ds[find(u[forest[i]])] = find(v[forest[i]]);
int sub = 0;
for (i = 0; i < tree.size(); i++) {
int pu = find(u[tree[i]]),pv = find(v[tree[i]]);
if (pu != pv) forest.pb(tree[i]),sub += royal[tree[i]],ds[pu] = pv;
}
return count_common_roads(forest)-sub;
}
int findAll(vi &poss,vi &u,vi &v,int n,int l,int r,int s) {
if (s == 0) {
int i;
for (i = l; i <= r; i++) royal[poss[i]] = 0;
return 0;
}
if (l == r) {
royal[poss[l]] = 1;
return 0;
}
int i,m = (l+r) / 2;
vi ask;
for (i = l; i <= m; i++) ask.pb(poss[i]);
int ls = query(ask,u,v,n);
findAll(poss,u,v,n,l,m,ls);
findAll(poss,u,v,n,m+1,r,s-ls);
return 0;
}
vector<int> find_roads(int n,vector<int> u,vector<int> v) {
int i,j;
memset(label,-1,sizeof(label));
memset(royal,-1,sizeof(royal));
for (i = 0; i < u.size(); i++) {
label[u[i]][v[i]] = label[v[i]][u[i]] = i;
adjList[u[i]].pb(v[i]);
adjList[v[i]].pb(u[i]);
}
for (i = 0; i < n; i++) disc[i] = low[i] = -1;
doDFS(0,-1);
while (!S.empty()) {
int w = S.back();
S.pop_back();
com[w] = bcc;
}
bcc++;
int t = count_common_roads(tree);
for (i = 0; i < bcc; i++) s[i] = r[i] = -1;
for (i = 1; i < n; i++) {
int u = label[i][parent[i]],v = lowlabel[i];
if (com[i] == com[parent[i]]) {
int p = find(tree.begin(),tree.end(),u)-tree.begin();
tree[p] = v;
int t2 = count_common_roads(tree);
tree[p] = u;
adjList2[u].pb(mp(v,t2-t));
adjList2[v].pb(mp(u,t-t2));
if (t != t2) s[com[i]] = u,r[com[i]] = (t > t2);
int w = i;
while (disc[parent[w]] != low[i]) w = parent[w];
w = label[w][parent[w]];
p = find(tree.begin(),tree.end(),w)-tree.begin();
tree[p] = v;
t2 = count_common_roads(tree);
tree[p] = w;
adjList2[w].pb(mp(v,t2-t));
adjList2[v].pb(mp(w,t-t2));
if (t != t2) s[com[i]] = w,r[com[i]] = (t > t2);
first[com[i]] = u;
}
else royal[u] = 1;
}
for (i = 0; i < bcc; i++) {
if (s[i] == -1) s[i] = first[i],r[i] = 0;
doDFS2(s[i],r[i]);
}
for (i = 0; i < n; i++) {
vi poss;
for (j = 0; j < adjList[i].size(); j++) {
int v = adjList[i][j];
if ((v > i) && (royal[label[i][v]] == -1)) poss.pb(label[i][v]);
}
findAll(poss,u,v,n,0,poss.size()-1,query(poss,u,v,n));
}
vi ans;
for (i = 0; i < u.size(); i++) {
if (royal[i]) ans.pb(i);
}
return ans;
}
Compilation message
simurgh.cpp: In function 'int doDFS(int, int)':
simurgh.cpp:69:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'int doDFS2(int, int)':
simurgh.cpp:95:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList2[u].size(); i++) doDFS2(adjList2[u][i].first,rr+adjList2[u][i].second);
~~^~~~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'int query(vi, vi&, vi&, int)':
simurgh.cpp:106:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < forest.size(); i++) ds[find(u[forest[i]])] = find(v[forest[i]]);
~~^~~~~~~~~~~~~~~
simurgh.cpp:108:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < tree.size(); i++) {
~~^~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:137:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < u.size(); i++) {
~~^~~~~~~~~~
simurgh.cpp:182:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < adjList[i].size(); j++) {
~~^~~~~~~~~~~~~~~~~~~
simurgh.cpp:189:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < u.size(); i++) {
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4728 KB |
correct |
2 |
Correct |
7 ms |
4968 KB |
correct |
3 |
Correct |
7 ms |
4968 KB |
correct |
4 |
Correct |
7 ms |
4968 KB |
correct |
5 |
Correct |
7 ms |
4968 KB |
correct |
6 |
Correct |
6 ms |
5020 KB |
correct |
7 |
Correct |
7 ms |
5020 KB |
correct |
8 |
Correct |
7 ms |
5020 KB |
correct |
9 |
Correct |
7 ms |
5020 KB |
correct |
10 |
Correct |
7 ms |
5084 KB |
correct |
11 |
Correct |
7 ms |
5088 KB |
correct |
12 |
Correct |
7 ms |
5088 KB |
correct |
13 |
Correct |
7 ms |
5088 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4728 KB |
correct |
2 |
Correct |
7 ms |
4968 KB |
correct |
3 |
Correct |
7 ms |
4968 KB |
correct |
4 |
Correct |
7 ms |
4968 KB |
correct |
5 |
Correct |
7 ms |
4968 KB |
correct |
6 |
Correct |
6 ms |
5020 KB |
correct |
7 |
Correct |
7 ms |
5020 KB |
correct |
8 |
Correct |
7 ms |
5020 KB |
correct |
9 |
Correct |
7 ms |
5020 KB |
correct |
10 |
Correct |
7 ms |
5084 KB |
correct |
11 |
Correct |
7 ms |
5088 KB |
correct |
12 |
Correct |
7 ms |
5088 KB |
correct |
13 |
Correct |
7 ms |
5088 KB |
correct |
14 |
Correct |
8 ms |
5120 KB |
correct |
15 |
Correct |
7 ms |
5128 KB |
correct |
16 |
Correct |
9 ms |
5128 KB |
correct |
17 |
Correct |
7 ms |
5128 KB |
correct |
18 |
Correct |
6 ms |
5128 KB |
correct |
19 |
Correct |
9 ms |
5128 KB |
correct |
20 |
Correct |
7 ms |
5128 KB |
correct |
21 |
Correct |
8 ms |
5128 KB |
correct |
22 |
Correct |
8 ms |
5128 KB |
correct |
23 |
Correct |
9 ms |
5128 KB |
correct |
24 |
Correct |
7 ms |
5128 KB |
correct |
25 |
Correct |
11 ms |
5128 KB |
correct |
26 |
Correct |
7 ms |
5128 KB |
correct |
27 |
Correct |
9 ms |
5128 KB |
correct |
28 |
Correct |
9 ms |
5128 KB |
correct |
29 |
Correct |
8 ms |
5128 KB |
correct |
30 |
Correct |
8 ms |
5128 KB |
correct |
31 |
Correct |
9 ms |
5128 KB |
correct |
32 |
Correct |
8 ms |
5128 KB |
correct |
33 |
Correct |
9 ms |
5128 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4728 KB |
correct |
2 |
Correct |
7 ms |
4968 KB |
correct |
3 |
Correct |
7 ms |
4968 KB |
correct |
4 |
Correct |
7 ms |
4968 KB |
correct |
5 |
Correct |
7 ms |
4968 KB |
correct |
6 |
Correct |
6 ms |
5020 KB |
correct |
7 |
Correct |
7 ms |
5020 KB |
correct |
8 |
Correct |
7 ms |
5020 KB |
correct |
9 |
Correct |
7 ms |
5020 KB |
correct |
10 |
Correct |
7 ms |
5084 KB |
correct |
11 |
Correct |
7 ms |
5088 KB |
correct |
12 |
Correct |
7 ms |
5088 KB |
correct |
13 |
Correct |
7 ms |
5088 KB |
correct |
14 |
Correct |
8 ms |
5120 KB |
correct |
15 |
Correct |
7 ms |
5128 KB |
correct |
16 |
Correct |
9 ms |
5128 KB |
correct |
17 |
Correct |
7 ms |
5128 KB |
correct |
18 |
Correct |
6 ms |
5128 KB |
correct |
19 |
Correct |
9 ms |
5128 KB |
correct |
20 |
Correct |
7 ms |
5128 KB |
correct |
21 |
Correct |
8 ms |
5128 KB |
correct |
22 |
Correct |
8 ms |
5128 KB |
correct |
23 |
Correct |
9 ms |
5128 KB |
correct |
24 |
Correct |
7 ms |
5128 KB |
correct |
25 |
Correct |
11 ms |
5128 KB |
correct |
26 |
Correct |
7 ms |
5128 KB |
correct |
27 |
Correct |
9 ms |
5128 KB |
correct |
28 |
Correct |
9 ms |
5128 KB |
correct |
29 |
Correct |
8 ms |
5128 KB |
correct |
30 |
Correct |
8 ms |
5128 KB |
correct |
31 |
Correct |
9 ms |
5128 KB |
correct |
32 |
Correct |
8 ms |
5128 KB |
correct |
33 |
Correct |
9 ms |
5128 KB |
correct |
34 |
Correct |
47 ms |
6100 KB |
correct |
35 |
Correct |
42 ms |
6192 KB |
correct |
36 |
Correct |
32 ms |
6260 KB |
correct |
37 |
Correct |
13 ms |
6260 KB |
correct |
38 |
Correct |
39 ms |
6544 KB |
correct |
39 |
Correct |
35 ms |
6764 KB |
correct |
40 |
Correct |
30 ms |
6916 KB |
correct |
41 |
Correct |
40 ms |
7052 KB |
correct |
42 |
Correct |
55 ms |
7252 KB |
correct |
43 |
Correct |
20 ms |
7252 KB |
correct |
44 |
Correct |
21 ms |
7252 KB |
correct |
45 |
Correct |
24 ms |
7252 KB |
correct |
46 |
Correct |
20 ms |
7256 KB |
correct |
47 |
Correct |
16 ms |
7256 KB |
correct |
48 |
Correct |
11 ms |
7256 KB |
correct |
49 |
Correct |
12 ms |
7256 KB |
correct |
50 |
Correct |
17 ms |
7256 KB |
correct |
51 |
Correct |
22 ms |
7528 KB |
correct |
52 |
Correct |
25 ms |
7528 KB |
correct |
53 |
Correct |
20 ms |
7588 KB |
correct |
54 |
Correct |
23 ms |
7920 KB |
correct |
55 |
Correct |
25 ms |
7920 KB |
correct |
56 |
Correct |
29 ms |
8048 KB |
correct |
57 |
Correct |
22 ms |
8092 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8092 KB |
correct |
2 |
Correct |
9 ms |
8092 KB |
correct |
3 |
Correct |
100 ms |
10120 KB |
correct |
4 |
Correct |
163 ms |
11092 KB |
correct |
5 |
Correct |
210 ms |
11160 KB |
correct |
6 |
Correct |
144 ms |
11160 KB |
correct |
7 |
Correct |
126 ms |
11256 KB |
correct |
8 |
Correct |
115 ms |
11256 KB |
correct |
9 |
Correct |
145 ms |
11256 KB |
correct |
10 |
Correct |
151 ms |
11256 KB |
correct |
11 |
Correct |
204 ms |
11256 KB |
correct |
12 |
Correct |
148 ms |
11256 KB |
correct |
13 |
Correct |
7 ms |
11256 KB |
correct |
14 |
Correct |
145 ms |
11256 KB |
correct |
15 |
Correct |
191 ms |
11256 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4728 KB |
correct |
2 |
Correct |
7 ms |
4968 KB |
correct |
3 |
Correct |
7 ms |
4968 KB |
correct |
4 |
Correct |
7 ms |
4968 KB |
correct |
5 |
Correct |
7 ms |
4968 KB |
correct |
6 |
Correct |
6 ms |
5020 KB |
correct |
7 |
Correct |
7 ms |
5020 KB |
correct |
8 |
Correct |
7 ms |
5020 KB |
correct |
9 |
Correct |
7 ms |
5020 KB |
correct |
10 |
Correct |
7 ms |
5084 KB |
correct |
11 |
Correct |
7 ms |
5088 KB |
correct |
12 |
Correct |
7 ms |
5088 KB |
correct |
13 |
Correct |
7 ms |
5088 KB |
correct |
14 |
Correct |
8 ms |
5120 KB |
correct |
15 |
Correct |
7 ms |
5128 KB |
correct |
16 |
Correct |
9 ms |
5128 KB |
correct |
17 |
Correct |
7 ms |
5128 KB |
correct |
18 |
Correct |
6 ms |
5128 KB |
correct |
19 |
Correct |
9 ms |
5128 KB |
correct |
20 |
Correct |
7 ms |
5128 KB |
correct |
21 |
Correct |
8 ms |
5128 KB |
correct |
22 |
Correct |
8 ms |
5128 KB |
correct |
23 |
Correct |
9 ms |
5128 KB |
correct |
24 |
Correct |
7 ms |
5128 KB |
correct |
25 |
Correct |
11 ms |
5128 KB |
correct |
26 |
Correct |
7 ms |
5128 KB |
correct |
27 |
Correct |
9 ms |
5128 KB |
correct |
28 |
Correct |
9 ms |
5128 KB |
correct |
29 |
Correct |
8 ms |
5128 KB |
correct |
30 |
Correct |
8 ms |
5128 KB |
correct |
31 |
Correct |
9 ms |
5128 KB |
correct |
32 |
Correct |
8 ms |
5128 KB |
correct |
33 |
Correct |
9 ms |
5128 KB |
correct |
34 |
Correct |
47 ms |
6100 KB |
correct |
35 |
Correct |
42 ms |
6192 KB |
correct |
36 |
Correct |
32 ms |
6260 KB |
correct |
37 |
Correct |
13 ms |
6260 KB |
correct |
38 |
Correct |
39 ms |
6544 KB |
correct |
39 |
Correct |
35 ms |
6764 KB |
correct |
40 |
Correct |
30 ms |
6916 KB |
correct |
41 |
Correct |
40 ms |
7052 KB |
correct |
42 |
Correct |
55 ms |
7252 KB |
correct |
43 |
Correct |
20 ms |
7252 KB |
correct |
44 |
Correct |
21 ms |
7252 KB |
correct |
45 |
Correct |
24 ms |
7252 KB |
correct |
46 |
Correct |
20 ms |
7256 KB |
correct |
47 |
Correct |
16 ms |
7256 KB |
correct |
48 |
Correct |
11 ms |
7256 KB |
correct |
49 |
Correct |
12 ms |
7256 KB |
correct |
50 |
Correct |
17 ms |
7256 KB |
correct |
51 |
Correct |
22 ms |
7528 KB |
correct |
52 |
Correct |
25 ms |
7528 KB |
correct |
53 |
Correct |
20 ms |
7588 KB |
correct |
54 |
Correct |
23 ms |
7920 KB |
correct |
55 |
Correct |
25 ms |
7920 KB |
correct |
56 |
Correct |
29 ms |
8048 KB |
correct |
57 |
Correct |
22 ms |
8092 KB |
correct |
58 |
Correct |
6 ms |
8092 KB |
correct |
59 |
Correct |
9 ms |
8092 KB |
correct |
60 |
Correct |
100 ms |
10120 KB |
correct |
61 |
Correct |
163 ms |
11092 KB |
correct |
62 |
Correct |
210 ms |
11160 KB |
correct |
63 |
Correct |
144 ms |
11160 KB |
correct |
64 |
Correct |
126 ms |
11256 KB |
correct |
65 |
Correct |
115 ms |
11256 KB |
correct |
66 |
Correct |
145 ms |
11256 KB |
correct |
67 |
Correct |
151 ms |
11256 KB |
correct |
68 |
Correct |
204 ms |
11256 KB |
correct |
69 |
Correct |
148 ms |
11256 KB |
correct |
70 |
Correct |
7 ms |
11256 KB |
correct |
71 |
Correct |
145 ms |
11256 KB |
correct |
72 |
Correct |
191 ms |
11256 KB |
correct |
73 |
Correct |
7 ms |
11256 KB |
correct |
74 |
Correct |
184 ms |
11256 KB |
correct |
75 |
Correct |
162 ms |
11256 KB |
correct |
76 |
Correct |
87 ms |
11256 KB |
correct |
77 |
Correct |
163 ms |
11256 KB |
correct |
78 |
Correct |
168 ms |
11256 KB |
correct |
79 |
Correct |
175 ms |
11256 KB |
correct |
80 |
Correct |
174 ms |
11256 KB |
correct |
81 |
Correct |
134 ms |
11256 KB |
correct |
82 |
Correct |
169 ms |
11256 KB |
correct |
83 |
Correct |
103 ms |
11256 KB |
correct |
84 |
Correct |
70 ms |
11256 KB |
correct |
85 |
Correct |
68 ms |
11256 KB |
correct |
86 |
Correct |
65 ms |
11256 KB |
correct |
87 |
Correct |
46 ms |
11256 KB |
correct |
88 |
Correct |
42 ms |
11256 KB |
correct |
89 |
Correct |
47 ms |
11256 KB |
correct |
90 |
Correct |
39 ms |
11256 KB |
correct |
91 |
Correct |
24 ms |
11256 KB |
correct |
92 |
Correct |
21 ms |
11256 KB |
correct |
93 |
Correct |
73 ms |
11256 KB |
correct |
94 |
Correct |
69 ms |
11256 KB |
correct |
95 |
Correct |
70 ms |
11256 KB |
correct |
96 |
Correct |
49 ms |
11256 KB |
correct |
97 |
Correct |
48 ms |
11256 KB |
correct |
98 |
Correct |
64 ms |
11256 KB |
correct |
99 |
Correct |
49 ms |
11256 KB |
correct |
100 |
Correct |
33 ms |
11256 KB |
correct |
101 |
Correct |
29 ms |
11256 KB |
correct |
102 |
Correct |
74 ms |
11256 KB |
correct |
103 |
Correct |
77 ms |
11256 KB |
correct |
104 |
Correct |
81 ms |
11256 KB |
correct |
105 |
Correct |
78 ms |
11256 KB |
correct |