#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 505;
int n, m;
vector<array<int, 2>> g[maxn], tr[maxn];
vector<int> state, te, vis, used;
void pre(int v) {
vis[v] = 1;
for(auto [i, id] : g[v]) if(!vis[i]) {
pre(i);
used.push_back(id);
te[id] = 1;
tr[v].push_back({i, id});
tr[i].push_back({v, id});
}
}
vector<int> _path;
bool find(int v, int t) {
if(v == t) return true;
vis[v] = 1;
int ok = 0;
for(auto [i, id] : tr[v]) if(!vis[i]) {
if(find(i, t)) _path.push_back(id), ok = 1;
}
return ok;
}
vector<int> find_path(int u, int v) {
_path.clear();
vis.assign(n, 0);
find(u, v);
return _path;
}
int alter(int id, int nid) {
vector<int> t = used;
for(auto &i : t) if(i == id) swap(i, t.back());
t.pop_back();
t.push_back(nid);
int res = count_common_roads(t);
//cout << "====query====\n";
//for(auto i : t) cout << i << " "; cout << " :: " << res << endl;
return res;
}
std::vector<int> find_roads(int _n, std::vector<int> u, std::vector<int> v) {
for(int i = 0; i < u.size(); i++) g[u[i]].push_back({v[i], i});
for(int i = 0; i < u.size(); i++) g[v[i]].push_back({u[i], i});
n = _n;
m = u.size();
state.resize(m);
te.resize(m);
vis.resize(n);
pre(0);
//cout << "Init tree is ";
//for(auto i : used) cout << u[i] << " " << v[i] << '\n';
int init = count_common_roads(used);
//cout << "init " << init << endl;
for(int i = 0; i < m; i++) if(!te[i]) {
vector<int> t = find_path(u[i], v[i]);
//cout << "Determining " << u[i] << " " << v[i] << endl;
//cout << "Path:\n";
//for(auto i : t) cout << u[i] << " " << v[i] << " | " << i << " " << state[i] << '\n';
int det = 0;
for(auto id : t) {
if(state[id]) {
int tmp = alter(id, i);
if(state[id] == 2) det = 1+(tmp == init);
else det = 1+(tmp>init);
break;
}
}
//cout << "det is " << det << '\n';
if(det) {
state[i] = det;
for(auto &id : t) if(!state[id]) {
int tmp = alter(id, i);
if(det == 2) state[id] = 1+(tmp == init);
else state[id] = 1+(tmp<init);
}
continue;
}
vector<int> results;
int mx = init;
for(auto id : t) {
results.push_back(alter(id, i));
mx = max(mx, results.back());
}
//cout << "Here, " << mx << '\n';
for(int i = 0; i < t.size(); i++)
state[t[i]] = 1+(results[i]!=mx);
state[i] = 1+(init!=mx);
}
std::vector<int> r;
//for(int i = 0; i < m; i++) cout << state[i] << " "; cout << '\n';
for(int i = 0; i < m; i++) if(state[i] != 1) r.push_back(i);
//for(auto i : r) cout << i << '\n';
return r;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < u.size(); i++) g[u[i]].push_back({v[i], i});
~~^~~~~~~~~~
simurgh.cpp:46:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < u.size(); i++) g[v[i]].push_back({u[i], i});
~~^~~~~~~~~~
simurgh.cpp:91:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < t.size(); i++)
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
2 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
2 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 |
0 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
1 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 |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
2 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
2 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 |
0 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
1 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 |
213 ms |
1912 KB |
correct |
35 |
Correct |
206 ms |
1664 KB |
correct |
36 |
Correct |
143 ms |
1408 KB |
correct |
37 |
Correct |
9 ms |
384 KB |
correct |
38 |
Correct |
216 ms |
1912 KB |
correct |
39 |
Correct |
180 ms |
1664 KB |
correct |
40 |
Correct |
140 ms |
1408 KB |
correct |
41 |
Correct |
213 ms |
1912 KB |
correct |
42 |
Correct |
211 ms |
1792 KB |
correct |
43 |
Correct |
110 ms |
1280 KB |
correct |
44 |
Correct |
90 ms |
1024 KB |
correct |
45 |
Correct |
108 ms |
1144 KB |
correct |
46 |
Correct |
75 ms |
896 KB |
correct |
47 |
Correct |
34 ms |
640 KB |
correct |
48 |
Correct |
2 ms |
384 KB |
correct |
49 |
Correct |
14 ms |
384 KB |
correct |
50 |
Correct |
34 ms |
640 KB |
correct |
51 |
Correct |
116 ms |
1144 KB |
correct |
52 |
Correct |
88 ms |
1024 KB |
correct |
53 |
Correct |
76 ms |
896 KB |
correct |
54 |
Correct |
112 ms |
1280 KB |
correct |
55 |
Correct |
106 ms |
1024 KB |
correct |
56 |
Correct |
107 ms |
1024 KB |
correct |
57 |
Correct |
105 ms |
1024 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Incorrect |
168 ms |
4608 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 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 |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
2 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
2 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 |
0 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
1 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 |
213 ms |
1912 KB |
correct |
35 |
Correct |
206 ms |
1664 KB |
correct |
36 |
Correct |
143 ms |
1408 KB |
correct |
37 |
Correct |
9 ms |
384 KB |
correct |
38 |
Correct |
216 ms |
1912 KB |
correct |
39 |
Correct |
180 ms |
1664 KB |
correct |
40 |
Correct |
140 ms |
1408 KB |
correct |
41 |
Correct |
213 ms |
1912 KB |
correct |
42 |
Correct |
211 ms |
1792 KB |
correct |
43 |
Correct |
110 ms |
1280 KB |
correct |
44 |
Correct |
90 ms |
1024 KB |
correct |
45 |
Correct |
108 ms |
1144 KB |
correct |
46 |
Correct |
75 ms |
896 KB |
correct |
47 |
Correct |
34 ms |
640 KB |
correct |
48 |
Correct |
2 ms |
384 KB |
correct |
49 |
Correct |
14 ms |
384 KB |
correct |
50 |
Correct |
34 ms |
640 KB |
correct |
51 |
Correct |
116 ms |
1144 KB |
correct |
52 |
Correct |
88 ms |
1024 KB |
correct |
53 |
Correct |
76 ms |
896 KB |
correct |
54 |
Correct |
112 ms |
1280 KB |
correct |
55 |
Correct |
106 ms |
1024 KB |
correct |
56 |
Correct |
107 ms |
1024 KB |
correct |
57 |
Correct |
105 ms |
1024 KB |
correct |
58 |
Correct |
0 ms |
384 KB |
correct |
59 |
Correct |
0 ms |
384 KB |
correct |
60 |
Incorrect |
168 ms |
4608 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |