# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
284130 |
2020-08-26T21:59:49 Z |
duality |
Village (BOI20_village) |
C++11 |
|
177 ms |
14584 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 ----------
int N;
vi adjList[100000];
int size[100000],disc[100000],order[100000],num = 0;
int ans[100000],ans1 = 0;
LLI ans2 = 0;
int doDFS(int u,int p) {
int i;
size[u] = 1,disc[u] = num,order[num++] = u;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v != p) size[u] += doDFS(v,u),ans2 += 2*min(size[v],N-size[v]);
}
if (ans[u] == u) ans1 += 2,swap(ans[u],ans[(p == -1) ? adjList[u][0]:p]);
return size[u];
}
int main() {
int i;
int a,b;
scanf("%d",&N);
for (i = 0; i < N-1; i++) {
scanf("%d %d",&a,&b);
a--,b--;
adjList[a].pb(b);
adjList[b].pb(a);
}
for (i = 0; i < N; i++) ans[i] = i;
doDFS(0,-1);
printf("%d %lld\n",ans1,ans2);
for (i = 0; i < N; i++) printf("%d ",ans[i]+1);
printf("\n");
for (i = 0; i < N; i++) printf("%d ",order[(disc[i]+N/2) % N]+1);
printf("\n");
return 0;
}
Compilation message
Village.cpp: In function 'int doDFS(int, int)':
Village.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (i = 0; i < adjList[u].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~
Village.cpp: In function 'int main()':
Village.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
76 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
Village.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
78 | scanf("%d %d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
3 ms |
2720 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2724 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
3 ms |
2728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
3 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2792 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2688 KB |
Output is correct |
9 |
Correct |
3 ms |
2688 KB |
Output is correct |
10 |
Correct |
4 ms |
2720 KB |
Output is correct |
11 |
Correct |
3 ms |
2792 KB |
Output is correct |
12 |
Correct |
3 ms |
2688 KB |
Output is correct |
13 |
Correct |
3 ms |
2688 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
3 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2832 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
3 ms |
2688 KB |
Output is correct |
24 |
Correct |
3 ms |
2724 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 ms |
2688 KB |
Output is correct |
29 |
Correct |
3 ms |
2688 KB |
Output is correct |
30 |
Correct |
3 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
3 ms |
2720 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2724 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
3 ms |
2728 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
3 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2792 KB |
Output is correct |
23 |
Correct |
3 ms |
2688 KB |
Output is correct |
24 |
Correct |
3 ms |
2816 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2720 KB |
Output is correct |
28 |
Correct |
3 ms |
2792 KB |
Output is correct |
29 |
Correct |
3 ms |
2688 KB |
Output is correct |
30 |
Correct |
3 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
3 ms |
2688 KB |
Output is correct |
33 |
Correct |
3 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2832 KB |
Output is correct |
37 |
Correct |
3 ms |
2688 KB |
Output is correct |
38 |
Correct |
3 ms |
2688 KB |
Output is correct |
39 |
Correct |
2 ms |
2688 KB |
Output is correct |
40 |
Correct |
3 ms |
2688 KB |
Output is correct |
41 |
Correct |
3 ms |
2724 KB |
Output is correct |
42 |
Correct |
2 ms |
2688 KB |
Output is correct |
43 |
Correct |
3 ms |
2688 KB |
Output is correct |
44 |
Correct |
2 ms |
2688 KB |
Output is correct |
45 |
Correct |
3 ms |
2688 KB |
Output is correct |
46 |
Correct |
3 ms |
2688 KB |
Output is correct |
47 |
Correct |
3 ms |
2688 KB |
Output is correct |
48 |
Correct |
98 ms |
8424 KB |
Output is correct |
49 |
Correct |
100 ms |
8960 KB |
Output is correct |
50 |
Correct |
109 ms |
8952 KB |
Output is correct |
51 |
Correct |
107 ms |
7548 KB |
Output is correct |
52 |
Correct |
128 ms |
8820 KB |
Output is correct |
53 |
Correct |
103 ms |
8260 KB |
Output is correct |
54 |
Correct |
59 ms |
8612 KB |
Output is correct |
55 |
Correct |
134 ms |
14584 KB |
Output is correct |
56 |
Correct |
177 ms |
11384 KB |
Output is correct |
57 |
Correct |
129 ms |
10600 KB |
Output is correct |
58 |
Correct |
124 ms |
9772 KB |
Output is correct |
59 |
Correct |
103 ms |
8952 KB |
Output is correct |
60 |
Correct |
79 ms |
9200 KB |
Output is correct |
61 |
Correct |
100 ms |
9180 KB |
Output is correct |
62 |
Correct |
87 ms |
9460 KB |
Output is correct |
63 |
Correct |
87 ms |
9080 KB |
Output is correct |
64 |
Correct |
104 ms |
9324 KB |
Output is correct |
65 |
Correct |
95 ms |
9468 KB |
Output is correct |
66 |
Correct |
81 ms |
9056 KB |
Output is correct |
67 |
Correct |
58 ms |
7716 KB |
Output is correct |
68 |
Correct |
93 ms |
8440 KB |
Output is correct |
69 |
Correct |
120 ms |
9464 KB |
Output is correct |
70 |
Correct |
90 ms |
9080 KB |
Output is correct |
71 |
Correct |
58 ms |
7444 KB |
Output is correct |
72 |
Correct |
70 ms |
8048 KB |
Output is correct |
73 |
Correct |
90 ms |
9464 KB |
Output is correct |
74 |
Correct |
79 ms |
8696 KB |
Output is correct |
75 |
Correct |
101 ms |
8564 KB |
Output is correct |
76 |
Correct |
104 ms |
8592 KB |
Output is correct |
77 |
Correct |
90 ms |
8792 KB |
Output is correct |
78 |
Correct |
62 ms |
6708 KB |
Output is correct |
79 |
Correct |
80 ms |
7360 KB |
Output is correct |
80 |
Correct |
107 ms |
8584 KB |
Output is correct |
81 |
Correct |
110 ms |
8912 KB |
Output is correct |
82 |
Correct |
91 ms |
8952 KB |
Output is correct |