This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
#define pb push_back
const int N = 505;
int par[N], vis[N], pos[N][N], cur[N], good[N][N], nw[N];
vector<int> E[N];
void dfs(int nd, int pr, vector<int>&vec){
par[nd] = pr;
vis[nd] = 1;
for (auto i : E[nd]){
if (!vis[i]){
vec.pb(pos[nd][i]);
cur[pos[nd][i]] = 1;
dfs(i, nd, vec);
}
}
}
int conv(vector<int> vec, int x, int y){
for (int i = 0; i < vec.size(); i++) if (vec[i] == x) vec[i] = y;
return count_common_roads(vec);
}
vector<int> find_roads(int n, vector<int> u, vector<int> v){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++) pos[i][j] = -1;
}
for (int i = 0; i < u.size(); i++){
u[i]++; v[i]++;
E[u[i]].pb(v[i]);
E[v[i]].pb(u[i]);
pos[u[i]][v[i]] = i;
pos[v[i]][u[i]] = i;
}
vector<int> vec;
dfs(1, 0, vec);
// for (auto i : vec){
// cout << i << " ";
// }
int prev = count_common_roads(vec);
// cout << prev << '\n';
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if (pos[i][j] == -1 or cur[pos[i][j]]) continue;
int a = j, b = par[j];
while(b){
int x = conv(vec, pos[a][b], pos[i][j]);
if (x != prev){
if (prev+1 == x){
good[i][j] = good[j][i] = 1;
}else if (prev-1 == x){
nw[pos[a][b]] = 1;
}
break;
}else{
a = b;
b = par[b];
}
}
}
}
vector<int> ans;
for (auto i : vec) if (nw[i]) ans.pb(i);
for (int i = 0; i < u.size(); i++){
if (good[u[i]][v[i]]) ans.pb(i);
}
return ans;
}
Compilation message (stderr)
simurgh.cpp: In function 'int conv(std::vector<int>, int, int)':
simurgh.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < vec.size(); i++) if (vec[i] == x) vec[i] = y;
| ~~^~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
simurgh.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |