#include <bits/stdc++.h>
#include "simurgh.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) a.size()
#define md(a, b) ((a) % b + b) % b
#define mod(a) md(a, MOD)
#define srt(a) sort(all(a))
#define mem(a, h) memset(a, (h), sizeof(a))
#define f first
#define s second
#define forn(i, n) for(int i = 0; i < n; i++)
#define fore(i, b, e) for(int i = b; i < e; i++)
#define forg(i, b, e, m) for(int i = b; i < e; i+=m)
//int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest order_of_key <
const int tam = 550;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1);
vector<pair<int, int>> g[tam];
vector<pair<int, int>> ng[tam];
vector<int> r;
int parent[tam * tam];
int color[tam * tam];
bool visited[tam], used[tam * tam], vasited[tam * tam];
int poso[tam * tam];
int con = 0;
int n, m;
void dfs0(int node)
{
visited[node] = 1;
fore(i, 0, g[node].size())
{
if(!visited[g[node][i].f])
{
r.pb(g[node][i].s);
used[g[node][i].s] = 1;
poso[g[node][i].s] = r.size() - 1;
ng[node].pb(g[node][i]);
ng[g[node][i].f].pb({node, g[node][i].s});
dfs0(g[node][i].f);
}
}
}
int find(int n)
{
if(parent[n] == -1) return n;
return parent[n] = find(parent[n]);
}
vector<int> res;
bool cicl(int node, int par)
{
visited[node] = 1;
//cout<<node<<'\n';
for(auto cat : ng[node])
{
if(!visited[cat.f])
{
if(cicl(cat.f, node))
{
//cout<<"++++++ "<<node<<' '<<cat.f<<' '<<cat.s<<'\n';
res.pb(cat.s);
return true;
}
}
else if(cat.f != par)
{
//cout<<"====== "<<node<<' '<<cat.f<<' '<<cat.s<<'\n';
res.pb(cat.s);
return true;
}
}
return false;
}
vector<int> find_roads(int nn, vector<int> u, vector<int> v) {
n = nn;
m = u.size();
fore(i, 0, m)
{
g[u[i]].pb({v[i], i});
g[v[i]].pb({u[i], i});
}
dfs0(0);
int x = count_common_roads(r), y, a, b;
if(x == n - 1) return r;
//cout<<r.size()<<' '<<x<<'\n';
/*fore(i, 0, r.size())
{
cout<<r[i]<<','<<poso[r[i]]<<" ";
}
cout<<'\n';*/
int remp;
int cont, sel;
mem(parent, -1);
bool bon;
fore(i, 0, m)
{
if(!used[i])
{
//cout<<i<<' '<<v[i]<<' '<<u[i]<<'\n';
ng[u[i]].pb({v[i], i});
ng[v[i]].pb({u[i], i});
fore(i, 0, n) visited[i] = 0;
res.clear();
cicl(u[i], -1);
ng[u[i]].pop_back();
ng[v[i]].pop_back();
vasited[i] = 1;
cont = 0;
//cout<<res.size()<<'\n';
//cout<<"mi ciclo "<<res[0]<<'\n';
bon = false;
fore(j, 1, res.size())
{
//cout<<res[j]<<','<<poso[res[j]]<<','<<r[poso[res[j]]]<<' ';
remp = res[j];
if(vasited[remp])
sel = remp;
else
{
r[poso[remp]] = i;
y = count_common_roads(r);
if(y == x)
{
cont++;
a = find(i);
b = find(remp);
if(a != b)
{
if(color[b] == 0)
color[b] = color[a];
parent[a] = b;
}
}
else if(y == x + 1)
{
bon = true;
color[find(i)] = 1;
color[find(remp)] = -1;
}
else
{
bon = true;
color[find(i)] = -1;
color[find(remp)] = 1;
}
r[poso[remp]] = remp;
}
vasited[remp] = 1;
}
//cout<<"\n\n";
if(cont == res.size() - 1)
color[find(i)] = -1;
else if(!bon)
{
remp = sel;
r[poso[remp]] = i;
y = count_common_roads(r);
if(y == x)
{
a = find(i);
b = find(remp);
if(a != b)
{
if(color[a] == 0)
color[a] = color[b];
parent[a] = b;
}
}
else if(y == x + 1)
{
bon = true;
color[find(i)] = 1;
color[find(remp)] = -1;
}
else
{
bon = true;
color[find(i)] = -1;
color[find(remp)] = 1;
}
r[poso[remp]] = remp;
}
}
}
//cout<<"hola\n";
r.clear();
fore(i, 0, m)
{
color[i] = color[find(i)];
//cout<<u[i]<<'-'<<v[i]<<' '<<i<<" color -> "<<color[i]<<'\n';
if(color[i] >= 0)
{
color[i] = 1;
//cout<<i<<'\n';
r.pb(i);
}
//cout<<u[i]<<'-'<<v[i]<<' '<<i<<" color -> "<<color[i]<<'\n';
}
//cout<<"cocacola\n";
//cout<<"el mio "<<r.size()<<'\n';
//fore(i, 0, r.size())
//cout<<r[i]<<' ';
//cout<<"\n\n";
return r;
}
Compilation message
simurgh.cpp: In function 'void dfs0(int)':
simurgh.cpp:16:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | #define fore(i, b, e) for(int i = b; i < e; i++)
......
49 | fore(i, 0, g[node].size())
| ~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:49:2: note: in expansion of macro 'fore'
49 | fore(i, 0, g[node].size())
| ^~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:16:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | #define fore(i, b, e) for(int i = b; i < e; i++)
......
130 | fore(j, 1, res.size())
| ~~~~~~~~~~~~~~~~
simurgh.cpp:130:4: note: in expansion of macro 'fore'
130 | fore(j, 1, res.size())
| ^~~~
simurgh.cpp:169:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
169 | if(cont == res.size() - 1)
| ~~~~~^~~~~~~~~~~~~~~~~
simurgh.cpp:64:13: warning: 'sel' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | if(parent[n] == -1) return n;
| ~~~~~~~~^
simurgh.cpp:110:12: note: 'sel' was declared here
110 | int cont, sel;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
correct |
2 |
Correct |
1 ms |
1536 KB |
correct |
3 |
Correct |
1 ms |
1536 KB |
correct |
4 |
Correct |
1 ms |
1536 KB |
correct |
5 |
Correct |
1 ms |
1536 KB |
correct |
6 |
Correct |
1 ms |
1536 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
1536 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
1536 KB |
correct |
13 |
Correct |
1 ms |
1536 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
correct |
2 |
Correct |
1 ms |
1536 KB |
correct |
3 |
Correct |
1 ms |
1536 KB |
correct |
4 |
Correct |
1 ms |
1536 KB |
correct |
5 |
Correct |
1 ms |
1536 KB |
correct |
6 |
Correct |
1 ms |
1536 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
1536 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
1536 KB |
correct |
13 |
Correct |
1 ms |
1536 KB |
correct |
14 |
Correct |
4 ms |
1536 KB |
correct |
15 |
Correct |
3 ms |
1536 KB |
correct |
16 |
Correct |
4 ms |
1536 KB |
correct |
17 |
Correct |
3 ms |
1536 KB |
correct |
18 |
Correct |
2 ms |
1536 KB |
correct |
19 |
Correct |
3 ms |
1536 KB |
correct |
20 |
Correct |
4 ms |
1536 KB |
correct |
21 |
Correct |
3 ms |
1536 KB |
correct |
22 |
Correct |
3 ms |
1536 KB |
correct |
23 |
Correct |
2 ms |
1536 KB |
correct |
24 |
Correct |
2 ms |
1536 KB |
correct |
25 |
Correct |
1 ms |
1536 KB |
correct |
26 |
Correct |
2 ms |
1536 KB |
correct |
27 |
Correct |
2 ms |
1536 KB |
correct |
28 |
Correct |
2 ms |
1536 KB |
correct |
29 |
Correct |
1 ms |
1536 KB |
correct |
30 |
Correct |
3 ms |
1536 KB |
correct |
31 |
Correct |
3 ms |
1536 KB |
correct |
32 |
Correct |
2 ms |
1536 KB |
correct |
33 |
Correct |
2 ms |
1536 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
correct |
2 |
Correct |
1 ms |
1536 KB |
correct |
3 |
Correct |
1 ms |
1536 KB |
correct |
4 |
Correct |
1 ms |
1536 KB |
correct |
5 |
Correct |
1 ms |
1536 KB |
correct |
6 |
Correct |
1 ms |
1536 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
1536 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
1536 KB |
correct |
13 |
Correct |
1 ms |
1536 KB |
correct |
14 |
Correct |
4 ms |
1536 KB |
correct |
15 |
Correct |
3 ms |
1536 KB |
correct |
16 |
Correct |
4 ms |
1536 KB |
correct |
17 |
Correct |
3 ms |
1536 KB |
correct |
18 |
Correct |
2 ms |
1536 KB |
correct |
19 |
Correct |
3 ms |
1536 KB |
correct |
20 |
Correct |
4 ms |
1536 KB |
correct |
21 |
Correct |
3 ms |
1536 KB |
correct |
22 |
Correct |
3 ms |
1536 KB |
correct |
23 |
Correct |
2 ms |
1536 KB |
correct |
24 |
Correct |
2 ms |
1536 KB |
correct |
25 |
Correct |
1 ms |
1536 KB |
correct |
26 |
Correct |
2 ms |
1536 KB |
correct |
27 |
Correct |
2 ms |
1536 KB |
correct |
28 |
Correct |
2 ms |
1536 KB |
correct |
29 |
Correct |
1 ms |
1536 KB |
correct |
30 |
Correct |
3 ms |
1536 KB |
correct |
31 |
Correct |
3 ms |
1536 KB |
correct |
32 |
Correct |
2 ms |
1536 KB |
correct |
33 |
Correct |
2 ms |
1536 KB |
correct |
34 |
Correct |
260 ms |
2796 KB |
correct |
35 |
Correct |
251 ms |
2704 KB |
correct |
36 |
Correct |
163 ms |
2552 KB |
correct |
37 |
Correct |
12 ms |
1664 KB |
correct |
38 |
Correct |
246 ms |
2792 KB |
correct |
39 |
Correct |
209 ms |
2656 KB |
correct |
40 |
Correct |
164 ms |
2552 KB |
correct |
41 |
Correct |
255 ms |
2808 KB |
correct |
42 |
Correct |
249 ms |
2680 KB |
correct |
43 |
Correct |
129 ms |
2304 KB |
correct |
44 |
Correct |
104 ms |
2048 KB |
correct |
45 |
Correct |
120 ms |
2176 KB |
correct |
46 |
Correct |
99 ms |
2048 KB |
correct |
47 |
Correct |
46 ms |
1792 KB |
correct |
48 |
Correct |
4 ms |
1536 KB |
correct |
49 |
Correct |
13 ms |
1664 KB |
correct |
50 |
Correct |
41 ms |
1792 KB |
correct |
51 |
Correct |
137 ms |
2168 KB |
correct |
52 |
Correct |
103 ms |
2168 KB |
correct |
53 |
Correct |
177 ms |
2084 KB |
correct |
54 |
Correct |
127 ms |
2304 KB |
correct |
55 |
Correct |
131 ms |
2168 KB |
correct |
56 |
Correct |
137 ms |
2296 KB |
correct |
57 |
Correct |
125 ms |
2168 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
416 KB |
correct |
2 |
Correct |
1 ms |
1536 KB |
correct |
3 |
Incorrect |
212 ms |
4808 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
correct |
2 |
Correct |
1 ms |
1536 KB |
correct |
3 |
Correct |
1 ms |
1536 KB |
correct |
4 |
Correct |
1 ms |
1536 KB |
correct |
5 |
Correct |
1 ms |
1536 KB |
correct |
6 |
Correct |
1 ms |
1536 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
1536 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
1536 KB |
correct |
13 |
Correct |
1 ms |
1536 KB |
correct |
14 |
Correct |
4 ms |
1536 KB |
correct |
15 |
Correct |
3 ms |
1536 KB |
correct |
16 |
Correct |
4 ms |
1536 KB |
correct |
17 |
Correct |
3 ms |
1536 KB |
correct |
18 |
Correct |
2 ms |
1536 KB |
correct |
19 |
Correct |
3 ms |
1536 KB |
correct |
20 |
Correct |
4 ms |
1536 KB |
correct |
21 |
Correct |
3 ms |
1536 KB |
correct |
22 |
Correct |
3 ms |
1536 KB |
correct |
23 |
Correct |
2 ms |
1536 KB |
correct |
24 |
Correct |
2 ms |
1536 KB |
correct |
25 |
Correct |
1 ms |
1536 KB |
correct |
26 |
Correct |
2 ms |
1536 KB |
correct |
27 |
Correct |
2 ms |
1536 KB |
correct |
28 |
Correct |
2 ms |
1536 KB |
correct |
29 |
Correct |
1 ms |
1536 KB |
correct |
30 |
Correct |
3 ms |
1536 KB |
correct |
31 |
Correct |
3 ms |
1536 KB |
correct |
32 |
Correct |
2 ms |
1536 KB |
correct |
33 |
Correct |
2 ms |
1536 KB |
correct |
34 |
Correct |
260 ms |
2796 KB |
correct |
35 |
Correct |
251 ms |
2704 KB |
correct |
36 |
Correct |
163 ms |
2552 KB |
correct |
37 |
Correct |
12 ms |
1664 KB |
correct |
38 |
Correct |
246 ms |
2792 KB |
correct |
39 |
Correct |
209 ms |
2656 KB |
correct |
40 |
Correct |
164 ms |
2552 KB |
correct |
41 |
Correct |
255 ms |
2808 KB |
correct |
42 |
Correct |
249 ms |
2680 KB |
correct |
43 |
Correct |
129 ms |
2304 KB |
correct |
44 |
Correct |
104 ms |
2048 KB |
correct |
45 |
Correct |
120 ms |
2176 KB |
correct |
46 |
Correct |
99 ms |
2048 KB |
correct |
47 |
Correct |
46 ms |
1792 KB |
correct |
48 |
Correct |
4 ms |
1536 KB |
correct |
49 |
Correct |
13 ms |
1664 KB |
correct |
50 |
Correct |
41 ms |
1792 KB |
correct |
51 |
Correct |
137 ms |
2168 KB |
correct |
52 |
Correct |
103 ms |
2168 KB |
correct |
53 |
Correct |
177 ms |
2084 KB |
correct |
54 |
Correct |
127 ms |
2304 KB |
correct |
55 |
Correct |
131 ms |
2168 KB |
correct |
56 |
Correct |
137 ms |
2296 KB |
correct |
57 |
Correct |
125 ms |
2168 KB |
correct |
58 |
Correct |
1 ms |
416 KB |
correct |
59 |
Correct |
1 ms |
1536 KB |
correct |
60 |
Incorrect |
212 ms |
4808 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |