# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1077028 |
2024-08-26T21:17:22 Z |
vjudge1 |
Simurgh (IOI17_simurgh) |
C++17 |
|
1 ms |
860 KB |
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef pair<char, int> ci;
typedef pair<string, int> si;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
#define pb push_back
#define fi first
#define se second
#define whole(v) v.begin(), v.end()
#define rwhole(v) v.rbegin(), v.rend()
#define inf INT_MAX/2
#define fro front
vi ans;
vector<vii> x(501);
ii fa[501];
int rs[125001];
int vis[501];
vi tree;
int z;
void df(int no, int f,int ideje){
if(ideje != -1){
tree.pb(ideje);
}
fa[no] = ii(f, ideje);
vis[no] = 1;
for(auto e:x[no]){
if(vis[e.fi]){
continue;
}
df(e.fi, no, e.se);
}
}
void dfs(int no){
vis[no] = 1;
for(auto e:x[no]){
if(vis[e.fi] == 1){
int f = no;
while(f != e.fi){
int ff = f;
f = fa[f].fi;
if(rs[fa[ff].se] != -1){
vi tre = tree;
for(int i = 0; i < tre.size(); ++i){
if(tre[i] == fa[ff].se){
tre[i] = e.se;
}
}
int g = count_common_roads(tre);
if(g == z){
rs[e.se] = rs[fa[ff].se];
}else if(g == z+1){
rs[e.se] = 1;
}else{
rs[e.se] = 0;
}
f = e.fi;
}
}
if(rs[e.se] == -1){
f = no;
while(f != e.fi){
int ff = f;
f = fa[f].fi;
vi tre = tree;
for(int i = 0; i < tre.size(); ++i){
if(tre[i] == fa[ff].se){
tre[i] = e.se;
}
}
int g = count_common_roads(tre);
if(g == z){
continue;
}else if(g == z+1){
rs[e.se] = 1;
rs[fa[ff].se] = 0;
f = e.fi;
}else{
rs[e.se] = 0;
rs[fa[ff].se] = 1;
f = e.fi;
}
}
}
while(f != e.fi){
int ff = f;
f = fa[f].fi;
if(rs[fa[ff].se] != -1){
continue;
}
vi tre = tree;
for(int i = 0; i < tre.size(); ++i){
if(tre[i] == fa[ff].se){
tre[i] = e.se;
}
}
int g = count_common_roads(tre);
if(g == z){
rs[fa[ff].se] = rs[e.se];
}else if(g == z+1){
rs[e.se] = 1;
rs[fa[ff].se] = 0;
f = e.fi;
}else{
rs[e.se] = 0;
rs[fa[ff].se] = 1;
f = e.fi;
}
}
continue;
}
dfs(e.fi);
}
vis[no] = 2;
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
for(int i = 0; i < u.size(); ++i){
x[u[i]].pb(ii(v[i], i));
x[v[i]].pb(ii(u[i], i));
}
fa[0] = ii(0, -1);
df(0, 0, -1);
memset(vis, 0, sizeof vis);
memset(rs, -1, sizeof rs);
z = count_common_roads(tree);
if(z == n-1){
return tree;
}
dfs(0);
//cout << 1 << endl;
for(auto e:tree){
if(rs[e] == -1){
rs[e] = 1;
}
}
for(int i = 0; i < 125001; ++i){
if(rs[i] == 1){
ans.pb(i);
}
}
/*for(auto e:ans){
cout << e << endl;
}*/
return ans;
}
Compilation message
simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:56:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < tre.size(); ++i){
| ~~^~~~~~~~~~~~
simurgh.cpp:78:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < tre.size(); ++i){
| ~~^~~~~~~~~~~~
simurgh.cpp:104:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int i = 0; i < tre.size(); ++i){
| ~~^~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:130:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | for(int i = 0; i < u.size(); ++i){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
856 KB |
correct |
2 |
Incorrect |
1 ms |
856 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |