#include "simurgh.h"
#include <bits/stdc++.h>
#define ad push_back
#define MP make_pair
#define fr first
#define sc second
#define ask count_common_roads
using namespace std;
const int N = 500 * 500 + 500;
int col[N], ind[N];
vector <pair <int, int> > g[N];
vector <int> sm;
vector <int> a[N], fp;
bool cl[N];
void dfs(int v)
{
a[v] = fp;
cl[v] = true;
for(auto p : g[v])
{
if(cl[p.fr]) continue;
ind[p.sc] = sm.size();
sm.ad(p.sc);
fp.ad(p.sc);
dfs(p.fr);
fp.pop_back();
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
for (int i = 0; i < u.size(); i++)
{
g[u[i]].ad(MP(v[i], i));
g[v[i]].ad(MP(u[i], i));
}
dfs(0);
//for(auto p : sm) cout << p << " ";
//cout << endl;
int ss = ask(sm);
for (int i = 0; i < u.size(); i++)
{
if((int)a[u[i]].size() <= (int)a[v[i]].size() + 1) swap(u[i], v[i]);
if((int)a[u[i]].size() <= (int)a[v[i]].size() + 1) continue;
//cout << i << endl;
vector <int> b;
for (int j = (int)a[v[i]].size(); j < (int)a[u[i]].size(); j++)
b.ad(a[u[i]][j]);
bool bl = false;
for(auto p : b)
{
if(col[p] == -1)
{
sm[ind[p]] = i;
if(ask(sm) == ss) col[i] = -1;
else col[i] = 1;
sm[ind[p]] = p;
bl = true;
break;
}
else if(col[p] == 1)
{
sm[ind[p]] = i;
if(ask(sm) == ss) col[i] = 1;
else col[i] = -1;
sm[ind[p]] = p;
bl = true;
break;
}
}
if(bl)
{
for(auto p : b)
{
if(col[p] == 0)
{
sm[ind[p]] = i;
if(ask(sm) == ss) col[p] = col[i];
else col[p] = -col[i];
sm[ind[p]] = p;
}
}
continue;
}
vector <pair<int, int> > c;
c.ad(MP(ss, i));
for(auto p : b)
{
sm[ind[p]] = i;
int i1 = ask(sm);
c.ad(MP(i1, p));
sm[ind[p]] = p;
}
sort(c.begin(), c.end());
if(c[0].fr == c.back().fr)
for(auto p : c) col[p.sc] = -1;
else
{
for(auto p : c)
{
if(c[0].fr == p.fr) col[p.sc] = 1;
else col[p.sc] = -1;
}
}
}
vector <int> pat;
for (int i = 0; i < u.size(); i++)
{
if(col[i] >= 0) pat.ad(i);
}
return pat;
}
/*
4 6
0 1
0 2
0 3
1 2
1 3
2 3
0 1 5
*/
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
simurgh.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
simurgh.cpp:107:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12160 KB |
correct |
2 |
Correct |
8 ms |
12160 KB |
correct |
3 |
Correct |
8 ms |
12152 KB |
correct |
4 |
Correct |
11 ms |
12136 KB |
correct |
5 |
Correct |
10 ms |
12160 KB |
correct |
6 |
Correct |
9 ms |
12160 KB |
correct |
7 |
Correct |
8 ms |
12032 KB |
correct |
8 |
Correct |
8 ms |
12032 KB |
correct |
9 |
Correct |
10 ms |
12032 KB |
correct |
10 |
Correct |
11 ms |
12160 KB |
correct |
11 |
Correct |
8 ms |
12032 KB |
correct |
12 |
Correct |
10 ms |
12032 KB |
correct |
13 |
Correct |
9 ms |
12160 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12160 KB |
correct |
2 |
Correct |
8 ms |
12160 KB |
correct |
3 |
Correct |
8 ms |
12152 KB |
correct |
4 |
Correct |
11 ms |
12136 KB |
correct |
5 |
Correct |
10 ms |
12160 KB |
correct |
6 |
Correct |
9 ms |
12160 KB |
correct |
7 |
Correct |
8 ms |
12032 KB |
correct |
8 |
Correct |
8 ms |
12032 KB |
correct |
9 |
Correct |
10 ms |
12032 KB |
correct |
10 |
Correct |
11 ms |
12160 KB |
correct |
11 |
Correct |
8 ms |
12032 KB |
correct |
12 |
Correct |
10 ms |
12032 KB |
correct |
13 |
Correct |
9 ms |
12160 KB |
correct |
14 |
Correct |
12 ms |
12156 KB |
correct |
15 |
Correct |
11 ms |
12160 KB |
correct |
16 |
Correct |
14 ms |
12160 KB |
correct |
17 |
Correct |
11 ms |
12160 KB |
correct |
18 |
Correct |
11 ms |
12160 KB |
correct |
19 |
Correct |
13 ms |
12160 KB |
correct |
20 |
Correct |
10 ms |
12160 KB |
correct |
21 |
Correct |
12 ms |
12192 KB |
correct |
22 |
Correct |
12 ms |
12160 KB |
correct |
23 |
Correct |
11 ms |
12288 KB |
correct |
24 |
Correct |
10 ms |
12160 KB |
correct |
25 |
Correct |
12 ms |
12160 KB |
correct |
26 |
Correct |
10 ms |
12160 KB |
correct |
27 |
Correct |
10 ms |
12160 KB |
correct |
28 |
Correct |
11 ms |
12160 KB |
correct |
29 |
Correct |
9 ms |
12160 KB |
correct |
30 |
Correct |
12 ms |
12136 KB |
correct |
31 |
Correct |
10 ms |
12160 KB |
correct |
32 |
Correct |
10 ms |
12160 KB |
correct |
33 |
Correct |
10 ms |
12160 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12160 KB |
correct |
2 |
Correct |
8 ms |
12160 KB |
correct |
3 |
Correct |
8 ms |
12152 KB |
correct |
4 |
Correct |
11 ms |
12136 KB |
correct |
5 |
Correct |
10 ms |
12160 KB |
correct |
6 |
Correct |
9 ms |
12160 KB |
correct |
7 |
Correct |
8 ms |
12032 KB |
correct |
8 |
Correct |
8 ms |
12032 KB |
correct |
9 |
Correct |
10 ms |
12032 KB |
correct |
10 |
Correct |
11 ms |
12160 KB |
correct |
11 |
Correct |
8 ms |
12032 KB |
correct |
12 |
Correct |
10 ms |
12032 KB |
correct |
13 |
Correct |
9 ms |
12160 KB |
correct |
14 |
Correct |
12 ms |
12156 KB |
correct |
15 |
Correct |
11 ms |
12160 KB |
correct |
16 |
Correct |
14 ms |
12160 KB |
correct |
17 |
Correct |
11 ms |
12160 KB |
correct |
18 |
Correct |
11 ms |
12160 KB |
correct |
19 |
Correct |
13 ms |
12160 KB |
correct |
20 |
Correct |
10 ms |
12160 KB |
correct |
21 |
Correct |
12 ms |
12192 KB |
correct |
22 |
Correct |
12 ms |
12160 KB |
correct |
23 |
Correct |
11 ms |
12288 KB |
correct |
24 |
Correct |
10 ms |
12160 KB |
correct |
25 |
Correct |
12 ms |
12160 KB |
correct |
26 |
Correct |
10 ms |
12160 KB |
correct |
27 |
Correct |
10 ms |
12160 KB |
correct |
28 |
Correct |
11 ms |
12160 KB |
correct |
29 |
Correct |
9 ms |
12160 KB |
correct |
30 |
Correct |
12 ms |
12136 KB |
correct |
31 |
Correct |
10 ms |
12160 KB |
correct |
32 |
Correct |
10 ms |
12160 KB |
correct |
33 |
Correct |
10 ms |
12160 KB |
correct |
34 |
Correct |
190 ms |
13608 KB |
correct |
35 |
Correct |
176 ms |
13440 KB |
correct |
36 |
Correct |
124 ms |
13232 KB |
correct |
37 |
Correct |
19 ms |
12288 KB |
correct |
38 |
Correct |
196 ms |
13560 KB |
correct |
39 |
Correct |
161 ms |
13432 KB |
correct |
40 |
Correct |
123 ms |
13304 KB |
correct |
41 |
Correct |
192 ms |
13628 KB |
correct |
42 |
Correct |
196 ms |
13476 KB |
correct |
43 |
Correct |
102 ms |
13056 KB |
correct |
44 |
Correct |
81 ms |
12800 KB |
correct |
45 |
Correct |
93 ms |
12800 KB |
correct |
46 |
Correct |
79 ms |
12672 KB |
correct |
47 |
Correct |
44 ms |
12408 KB |
correct |
48 |
Correct |
12 ms |
12160 KB |
correct |
49 |
Correct |
17 ms |
12288 KB |
correct |
50 |
Correct |
37 ms |
12416 KB |
correct |
51 |
Correct |
104 ms |
12800 KB |
correct |
52 |
Correct |
84 ms |
12800 KB |
correct |
53 |
Correct |
75 ms |
12672 KB |
correct |
54 |
Correct |
102 ms |
13040 KB |
correct |
55 |
Correct |
104 ms |
12920 KB |
correct |
56 |
Correct |
95 ms |
12920 KB |
correct |
57 |
Correct |
99 ms |
12920 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12032 KB |
correct |
2 |
Correct |
8 ms |
12160 KB |
correct |
3 |
Incorrect |
145 ms |
15480 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12160 KB |
correct |
2 |
Correct |
8 ms |
12160 KB |
correct |
3 |
Correct |
8 ms |
12152 KB |
correct |
4 |
Correct |
11 ms |
12136 KB |
correct |
5 |
Correct |
10 ms |
12160 KB |
correct |
6 |
Correct |
9 ms |
12160 KB |
correct |
7 |
Correct |
8 ms |
12032 KB |
correct |
8 |
Correct |
8 ms |
12032 KB |
correct |
9 |
Correct |
10 ms |
12032 KB |
correct |
10 |
Correct |
11 ms |
12160 KB |
correct |
11 |
Correct |
8 ms |
12032 KB |
correct |
12 |
Correct |
10 ms |
12032 KB |
correct |
13 |
Correct |
9 ms |
12160 KB |
correct |
14 |
Correct |
12 ms |
12156 KB |
correct |
15 |
Correct |
11 ms |
12160 KB |
correct |
16 |
Correct |
14 ms |
12160 KB |
correct |
17 |
Correct |
11 ms |
12160 KB |
correct |
18 |
Correct |
11 ms |
12160 KB |
correct |
19 |
Correct |
13 ms |
12160 KB |
correct |
20 |
Correct |
10 ms |
12160 KB |
correct |
21 |
Correct |
12 ms |
12192 KB |
correct |
22 |
Correct |
12 ms |
12160 KB |
correct |
23 |
Correct |
11 ms |
12288 KB |
correct |
24 |
Correct |
10 ms |
12160 KB |
correct |
25 |
Correct |
12 ms |
12160 KB |
correct |
26 |
Correct |
10 ms |
12160 KB |
correct |
27 |
Correct |
10 ms |
12160 KB |
correct |
28 |
Correct |
11 ms |
12160 KB |
correct |
29 |
Correct |
9 ms |
12160 KB |
correct |
30 |
Correct |
12 ms |
12136 KB |
correct |
31 |
Correct |
10 ms |
12160 KB |
correct |
32 |
Correct |
10 ms |
12160 KB |
correct |
33 |
Correct |
10 ms |
12160 KB |
correct |
34 |
Correct |
190 ms |
13608 KB |
correct |
35 |
Correct |
176 ms |
13440 KB |
correct |
36 |
Correct |
124 ms |
13232 KB |
correct |
37 |
Correct |
19 ms |
12288 KB |
correct |
38 |
Correct |
196 ms |
13560 KB |
correct |
39 |
Correct |
161 ms |
13432 KB |
correct |
40 |
Correct |
123 ms |
13304 KB |
correct |
41 |
Correct |
192 ms |
13628 KB |
correct |
42 |
Correct |
196 ms |
13476 KB |
correct |
43 |
Correct |
102 ms |
13056 KB |
correct |
44 |
Correct |
81 ms |
12800 KB |
correct |
45 |
Correct |
93 ms |
12800 KB |
correct |
46 |
Correct |
79 ms |
12672 KB |
correct |
47 |
Correct |
44 ms |
12408 KB |
correct |
48 |
Correct |
12 ms |
12160 KB |
correct |
49 |
Correct |
17 ms |
12288 KB |
correct |
50 |
Correct |
37 ms |
12416 KB |
correct |
51 |
Correct |
104 ms |
12800 KB |
correct |
52 |
Correct |
84 ms |
12800 KB |
correct |
53 |
Correct |
75 ms |
12672 KB |
correct |
54 |
Correct |
102 ms |
13040 KB |
correct |
55 |
Correct |
104 ms |
12920 KB |
correct |
56 |
Correct |
95 ms |
12920 KB |
correct |
57 |
Correct |
99 ms |
12920 KB |
correct |
58 |
Correct |
15 ms |
12032 KB |
correct |
59 |
Correct |
8 ms |
12160 KB |
correct |
60 |
Incorrect |
145 ms |
15480 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |