# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
22985 |
2017-05-01T02:38:58 Z |
model_code |
Network (BOI15_net) |
C++11 |
|
1136 ms |
64512 KB |
/*/
Task: net
Random solution
With covering edges
Author: Bartosz Kostka
/*/
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 500007;
vector <int> L,G[MAXN];
int w, n;
int licz;
int d[MAXN], par[MAXN];
bool vis[MAXN];
map <pair <int, int>, bool> M;
void print(vector <int> &S)
{
printf("%d\n", (int)S.size()/2);
for(int i=0; i<(int)S.size(); i+=2)
printf("%d %d\n", S[i], S[i+1]);
exit(0);
}
void dfs(int v)
{
vis[v] = true;
for(auto w : G[v])
if(vis[w] == false)
{
d[w] = d[v]+1;
par[w] = v;
dfs(w);
}
}
void sset(int a, int b, bool jak)
{
int x = min(a,b);
int y = max(a,b);
M[make_pair(x,y)] = jak;
}
void cover(int a, int b)
{
if(d[a] < d[b])
swap(a,b);
while(d[a] != d[b])
{
sset(a,par[a],true);
a = par[a];
}
while(a != b)
{
cerr << a << " " << b << "\n";
cerr << "P" << par[a] << " " << par[b] << "\n";
sset(a,par[a],true);
a = par[a];
sset(b,par[b],true);
b = par[b];
}
}
bool bridges()
{
cerr << "???\n";
for(auto ele : M)
if(ele.second == false)
return true;
return false;
}
int main()
{
srand(42);
scanf("%d", &n);
if(n==1)
{
printf("0\n");
return 0;
}
if(n==2)
{
printf("1\n1 2\n");
return 0;
}
for(int i=1; i<n; i++)
{
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
sset(a,b,false);
}
for(int i=1; i<=n; i++)
{
if((int)G[i].size() == 1)
L.push_back(i);
else
w = i;
}
dfs(w);
if((int)L.size() % 2 == 1)
L.push_back(w);
while(true)
{
random_shuffle(L.begin(), L.end());
for(int i=0; i<(int)L.size(); i+=2)
{
int a = L[i], b = L[i+1];
cerr << a << " " << b << "\n";
cover(a,b);
}
if(bridges() == false)
print(L);
for(auto& ele : M)
ele.second = false;
}
}
Compilation message
net.cpp: In function 'int main()':
net.cpp:81:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
net.cpp:95:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18140 KB |
Output is correct |
2 |
Correct |
0 ms |
18140 KB |
Output is correct |
3 |
Correct |
3 ms |
18140 KB |
Output is correct |
4 |
Correct |
0 ms |
18140 KB |
Output is correct |
5 |
Correct |
3 ms |
18140 KB |
Output is correct |
6 |
Correct |
6 ms |
18140 KB |
Output is correct |
7 |
Correct |
0 ms |
18140 KB |
Output is correct |
8 |
Correct |
0 ms |
18140 KB |
Output is correct |
9 |
Correct |
6 ms |
18140 KB |
Output is correct |
10 |
Correct |
0 ms |
18140 KB |
Output is correct |
11 |
Correct |
0 ms |
18140 KB |
Output is correct |
12 |
Correct |
6 ms |
18140 KB |
Output is correct |
13 |
Correct |
0 ms |
18140 KB |
Output is correct |
14 |
Correct |
0 ms |
18140 KB |
Output is correct |
15 |
Correct |
0 ms |
18140 KB |
Output is correct |
16 |
Correct |
3 ms |
18140 KB |
Output is correct |
17 |
Correct |
0 ms |
18140 KB |
Output is correct |
18 |
Correct |
0 ms |
18140 KB |
Output is correct |
19 |
Correct |
3 ms |
18140 KB |
Output is correct |
20 |
Correct |
0 ms |
18140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18140 KB |
Output is correct |
2 |
Correct |
0 ms |
18140 KB |
Output is correct |
3 |
Correct |
3 ms |
18140 KB |
Output is correct |
4 |
Correct |
0 ms |
18140 KB |
Output is correct |
5 |
Correct |
3 ms |
18140 KB |
Output is correct |
6 |
Correct |
6 ms |
18140 KB |
Output is correct |
7 |
Correct |
0 ms |
18140 KB |
Output is correct |
8 |
Correct |
0 ms |
18140 KB |
Output is correct |
9 |
Correct |
6 ms |
18140 KB |
Output is correct |
10 |
Correct |
0 ms |
18140 KB |
Output is correct |
11 |
Correct |
0 ms |
18140 KB |
Output is correct |
12 |
Correct |
6 ms |
18140 KB |
Output is correct |
13 |
Correct |
0 ms |
18140 KB |
Output is correct |
14 |
Correct |
0 ms |
18140 KB |
Output is correct |
15 |
Correct |
0 ms |
18140 KB |
Output is correct |
16 |
Correct |
3 ms |
18140 KB |
Output is correct |
17 |
Correct |
0 ms |
18140 KB |
Output is correct |
18 |
Correct |
0 ms |
18140 KB |
Output is correct |
19 |
Correct |
3 ms |
18140 KB |
Output is correct |
20 |
Correct |
0 ms |
18140 KB |
Output is correct |
21 |
Correct |
3 ms |
18140 KB |
Output is correct |
22 |
Correct |
36 ms |
18404 KB |
Output is correct |
23 |
Correct |
23 ms |
18404 KB |
Output is correct |
24 |
Correct |
16 ms |
18404 KB |
Output is correct |
25 |
Correct |
29 ms |
18404 KB |
Output is correct |
26 |
Correct |
13 ms |
18272 KB |
Output is correct |
27 |
Correct |
33 ms |
18404 KB |
Output is correct |
28 |
Correct |
29 ms |
18404 KB |
Output is correct |
29 |
Correct |
13 ms |
18272 KB |
Output is correct |
30 |
Correct |
3 ms |
18140 KB |
Output is correct |
31 |
Correct |
43 ms |
18404 KB |
Output is correct |
32 |
Correct |
0 ms |
18140 KB |
Output is correct |
33 |
Correct |
3 ms |
18140 KB |
Output is correct |
34 |
Correct |
3 ms |
18140 KB |
Output is correct |
35 |
Correct |
0 ms |
18140 KB |
Output is correct |
36 |
Correct |
0 ms |
18140 KB |
Output is correct |
37 |
Correct |
3 ms |
18272 KB |
Output is correct |
38 |
Correct |
19 ms |
18272 KB |
Output is correct |
39 |
Correct |
0 ms |
18140 KB |
Output is correct |
40 |
Correct |
0 ms |
18140 KB |
Output is correct |
41 |
Correct |
6 ms |
18140 KB |
Output is correct |
42 |
Correct |
3 ms |
18272 KB |
Output is correct |
43 |
Correct |
6 ms |
18272 KB |
Output is correct |
44 |
Correct |
0 ms |
18140 KB |
Output is correct |
45 |
Correct |
16 ms |
18140 KB |
Output is correct |
46 |
Correct |
19 ms |
18272 KB |
Output is correct |
47 |
Correct |
3 ms |
18140 KB |
Output is correct |
48 |
Correct |
0 ms |
18140 KB |
Output is correct |
49 |
Correct |
3 ms |
18272 KB |
Output is correct |
50 |
Correct |
0 ms |
18140 KB |
Output is correct |
51 |
Correct |
3 ms |
18140 KB |
Output is correct |
52 |
Correct |
9 ms |
18140 KB |
Output is correct |
53 |
Correct |
36 ms |
18272 KB |
Output is correct |
54 |
Correct |
6 ms |
18140 KB |
Output is correct |
55 |
Correct |
6 ms |
18140 KB |
Output is correct |
56 |
Correct |
0 ms |
18140 KB |
Output is correct |
57 |
Correct |
9 ms |
18272 KB |
Output is correct |
58 |
Correct |
33 ms |
18404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18140 KB |
Output is correct |
2 |
Correct |
0 ms |
18140 KB |
Output is correct |
3 |
Correct |
3 ms |
18140 KB |
Output is correct |
4 |
Correct |
0 ms |
18140 KB |
Output is correct |
5 |
Correct |
3 ms |
18140 KB |
Output is correct |
6 |
Correct |
6 ms |
18140 KB |
Output is correct |
7 |
Correct |
0 ms |
18140 KB |
Output is correct |
8 |
Correct |
0 ms |
18140 KB |
Output is correct |
9 |
Correct |
6 ms |
18140 KB |
Output is correct |
10 |
Correct |
0 ms |
18140 KB |
Output is correct |
11 |
Correct |
0 ms |
18140 KB |
Output is correct |
12 |
Correct |
6 ms |
18140 KB |
Output is correct |
13 |
Correct |
0 ms |
18140 KB |
Output is correct |
14 |
Correct |
0 ms |
18140 KB |
Output is correct |
15 |
Correct |
0 ms |
18140 KB |
Output is correct |
16 |
Correct |
3 ms |
18140 KB |
Output is correct |
17 |
Correct |
0 ms |
18140 KB |
Output is correct |
18 |
Correct |
0 ms |
18140 KB |
Output is correct |
19 |
Correct |
3 ms |
18140 KB |
Output is correct |
20 |
Correct |
0 ms |
18140 KB |
Output is correct |
21 |
Correct |
3 ms |
18140 KB |
Output is correct |
22 |
Correct |
36 ms |
18404 KB |
Output is correct |
23 |
Correct |
23 ms |
18404 KB |
Output is correct |
24 |
Correct |
16 ms |
18404 KB |
Output is correct |
25 |
Correct |
29 ms |
18404 KB |
Output is correct |
26 |
Correct |
13 ms |
18272 KB |
Output is correct |
27 |
Correct |
33 ms |
18404 KB |
Output is correct |
28 |
Correct |
29 ms |
18404 KB |
Output is correct |
29 |
Correct |
13 ms |
18272 KB |
Output is correct |
30 |
Correct |
3 ms |
18140 KB |
Output is correct |
31 |
Correct |
43 ms |
18404 KB |
Output is correct |
32 |
Correct |
0 ms |
18140 KB |
Output is correct |
33 |
Correct |
3 ms |
18140 KB |
Output is correct |
34 |
Correct |
3 ms |
18140 KB |
Output is correct |
35 |
Correct |
0 ms |
18140 KB |
Output is correct |
36 |
Correct |
0 ms |
18140 KB |
Output is correct |
37 |
Correct |
3 ms |
18272 KB |
Output is correct |
38 |
Correct |
19 ms |
18272 KB |
Output is correct |
39 |
Correct |
0 ms |
18140 KB |
Output is correct |
40 |
Correct |
0 ms |
18140 KB |
Output is correct |
41 |
Correct |
6 ms |
18140 KB |
Output is correct |
42 |
Correct |
3 ms |
18272 KB |
Output is correct |
43 |
Correct |
6 ms |
18272 KB |
Output is correct |
44 |
Correct |
0 ms |
18140 KB |
Output is correct |
45 |
Correct |
16 ms |
18140 KB |
Output is correct |
46 |
Correct |
19 ms |
18272 KB |
Output is correct |
47 |
Correct |
3 ms |
18140 KB |
Output is correct |
48 |
Correct |
0 ms |
18140 KB |
Output is correct |
49 |
Correct |
3 ms |
18272 KB |
Output is correct |
50 |
Correct |
0 ms |
18140 KB |
Output is correct |
51 |
Correct |
3 ms |
18140 KB |
Output is correct |
52 |
Correct |
9 ms |
18140 KB |
Output is correct |
53 |
Correct |
36 ms |
18272 KB |
Output is correct |
54 |
Correct |
6 ms |
18140 KB |
Output is correct |
55 |
Correct |
6 ms |
18140 KB |
Output is correct |
56 |
Correct |
0 ms |
18140 KB |
Output is correct |
57 |
Correct |
9 ms |
18272 KB |
Output is correct |
58 |
Correct |
33 ms |
18404 KB |
Output is correct |
59 |
Runtime error |
1136 ms |
64512 KB |
Execution timed out (wall clock limit exceeded) |
60 |
Halted |
0 ms |
0 KB |
- |