#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 250;
const int MAXM = 30010;
int n, m;
int depth[MAXN];
int isRoyal[MAXM];
int ancNode[MAXN], ancEdge[MAXN];
bool mark[MAXN];
bool DFSTree[MAXM];
vector<int> tree;
vector<int> adj[MAXN];
vector<int> indEdge[MAXN];
void DFS(int cur)
{
mark[cur] = true;
for(int i = 0 ; i < (int)adj[cur].size() ; i++)
{
int viz = adj[cur][i];
int ind = indEdge[cur][i];
if( mark[viz] ) continue;
DFSTree[ind] = true;
tree.push_back( ind );
ancNode[viz] = cur;
ancEdge[viz] = ind;
depth[viz] = depth[cur] + 1;
DFS( viz );
}
}
int query(int newEdge = -1, int blockEdge = -1)
{
vector<int> q;
if( newEdge != -1 ) q.push_back( newEdge );
for(int i = 0 ; i < (int)tree.size() ; i++)
if( tree[i] != blockEdge ) q.push_back( tree[i] );
return count_common_roads( q );
}
vector<int> find_roads(int N, vector<int> u, vector<int> v)
{
n = N; m = (int)u.size();
for(int i = 0 ; i < m ; i++)
{
adj[ u[i] ].push_back( v[i] );
adj[ v[i] ].push_back( u[i] );
indEdge[ u[i] ].push_back( i );
indEdge[ v[i] ].push_back( i );
isRoyal[i] = -1;
}
DFS( 1 );
int qtdRoyalTree = query();
for(int i = 0 ; i < m ; i++)
{
if( DFSTree[i] ) continue;
if( depth[ u[i] ] > depth[ v[i] ] )
swap( u[i] , v[i] );
int cur = v[i];
int known = -1;
vector<int> unknown;
while( cur != u[i] )
{
if( isRoyal[ ancEdge[cur] ] != -1 ) known = ancEdge[cur];
else unknown.push_back( ancEdge[cur] );
cur = ancNode[cur];
}
if( known != -1 )
{
int newQtd = query( i , known );
if( newQtd == qtdRoyalTree ) isRoyal[i] = isRoyal[known];
else isRoyal[i] = 1 - isRoyal[known];
for(int j = 0 ; j < (int)unknown.size() ; j++)
{
newQtd = query( i , unknown[j] );
if( newQtd == qtdRoyalTree ) isRoyal[ unknown[j] ] = isRoyal[i];
else isRoyal[ unknown[j] ] = 1 - isRoyal[i];
}
continue;
}
for(int j = 0 ; j < (int)unknown.size() ; j++)
{
int newQtd = query( i , unknown[j] );
if( isRoyal[i] != -1 )
{
if( newQtd == qtdRoyalTree ) isRoyal[ unknown[j] ] = isRoyal[i];
else isRoyal[ unknown[j] ] = 1 - isRoyal[i];
continue;
}
if( newQtd != qtdRoyalTree )
{
if( newQtd > qtdRoyalTree ) isRoyal[i] = 1;
else isRoyal[i] = 0;
isRoyal[ unknown[j] ] = 1 - isRoyal[i];
for(int k = 0 ; k < j ; k++)
isRoyal[ unknown[k] ] = isRoyal[i];
}
}
if( isRoyal[i] == -1 )
{
isRoyal[i] = 0;
for(int j = 0 ; j < (int)unknown.size() ; j++)
isRoyal[ unknown[j] ] = 0;
}
}
for(int i = 0 ; i < m ; i++)
if( isRoyal[i] == -1 ) isRoyal[i] = 1;
vector<int> ans;
for(int i = 0 ; i < m ; i++)
if( isRoyal[i] == 1 ) ans.push_back( i );
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
380 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
288 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
380 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
288 KB |
correct |
14 |
Correct |
3 ms |
416 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
1 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
416 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
380 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
288 KB |
correct |
14 |
Correct |
3 ms |
416 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
1 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
416 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
34 |
Correct |
197 ms |
1664 KB |
correct |
35 |
Correct |
197 ms |
1692 KB |
correct |
36 |
Correct |
129 ms |
1408 KB |
correct |
37 |
Correct |
9 ms |
384 KB |
correct |
38 |
Correct |
194 ms |
1784 KB |
correct |
39 |
Correct |
174 ms |
1536 KB |
correct |
40 |
Correct |
137 ms |
1408 KB |
correct |
41 |
Correct |
199 ms |
1784 KB |
correct |
42 |
Correct |
198 ms |
1712 KB |
correct |
43 |
Correct |
104 ms |
1152 KB |
correct |
44 |
Correct |
87 ms |
896 KB |
correct |
45 |
Correct |
97 ms |
1024 KB |
correct |
46 |
Correct |
81 ms |
928 KB |
correct |
47 |
Correct |
36 ms |
640 KB |
correct |
48 |
Correct |
3 ms |
384 KB |
correct |
49 |
Correct |
10 ms |
512 KB |
correct |
50 |
Correct |
36 ms |
640 KB |
correct |
51 |
Correct |
114 ms |
1024 KB |
correct |
52 |
Correct |
82 ms |
896 KB |
correct |
53 |
Correct |
77 ms |
896 KB |
correct |
54 |
Correct |
101 ms |
1152 KB |
correct |
55 |
Correct |
100 ms |
1144 KB |
correct |
56 |
Correct |
99 ms |
1024 KB |
correct |
57 |
Correct |
98 ms |
1024 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Runtime error |
23 ms |
3576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
380 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
0 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
288 KB |
correct |
14 |
Correct |
3 ms |
416 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
1 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
416 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
34 |
Correct |
197 ms |
1664 KB |
correct |
35 |
Correct |
197 ms |
1692 KB |
correct |
36 |
Correct |
129 ms |
1408 KB |
correct |
37 |
Correct |
9 ms |
384 KB |
correct |
38 |
Correct |
194 ms |
1784 KB |
correct |
39 |
Correct |
174 ms |
1536 KB |
correct |
40 |
Correct |
137 ms |
1408 KB |
correct |
41 |
Correct |
199 ms |
1784 KB |
correct |
42 |
Correct |
198 ms |
1712 KB |
correct |
43 |
Correct |
104 ms |
1152 KB |
correct |
44 |
Correct |
87 ms |
896 KB |
correct |
45 |
Correct |
97 ms |
1024 KB |
correct |
46 |
Correct |
81 ms |
928 KB |
correct |
47 |
Correct |
36 ms |
640 KB |
correct |
48 |
Correct |
3 ms |
384 KB |
correct |
49 |
Correct |
10 ms |
512 KB |
correct |
50 |
Correct |
36 ms |
640 KB |
correct |
51 |
Correct |
114 ms |
1024 KB |
correct |
52 |
Correct |
82 ms |
896 KB |
correct |
53 |
Correct |
77 ms |
896 KB |
correct |
54 |
Correct |
101 ms |
1152 KB |
correct |
55 |
Correct |
100 ms |
1144 KB |
correct |
56 |
Correct |
99 ms |
1024 KB |
correct |
57 |
Correct |
98 ms |
1024 KB |
correct |
58 |
Correct |
1 ms |
384 KB |
correct |
59 |
Correct |
1 ms |
384 KB |
correct |
60 |
Runtime error |
23 ms |
3576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
61 |
Halted |
0 ms |
0 KB |
- |