#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 501;
int vis[N] , vi = 0;
vector< pair<int,int> > g[N], T[N];
vector< int > tree , anss ;
bool ok[N * N] = {0};
int needed[N];
void DFS(int node,int prnt){
vis[node] = vi;
needed[node] = prnt;
for(int i=0;i<g[node].size();i++){
if(vis[g[node][i].first] != vi){
tree.push_back(g[node][i].second);
T[node].push_back(g[node][i]);
T[g[node][i].first].push_back(make_pair(node,g[node][i].second));
DFS(g[node][i].first,g[node][i].second);
}
}
}
bool DFS2(int node,int target,int cant){
if(node == target) return true;
vis[node] = vi;
for(int i=0;i<T[node].size();i++){
int newnode = T[node][i].first;
if(newnode != cant && vis[newnode] != vi && DFS2(newnode,target,cant)) return true;
}
return false;
}
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(make_pair(v[i],i));
g[v[i]].push_back(make_pair(u[i],i));
}
vi++;
DFS(0,-1);
int res = count_common_roads(tree);
for(int i=0;i<n;i++){
vector< pair<int,int> > v;
int mx = 0 ;
for(int j=0;j<g[i].size();j++){
int newnode = g[i][j].first;
int edge = -1;
for(int k=0;k<T[i].size();k++){
vi++;
if(DFS2(T[i][k].first,newnode,i)){
edge = T[i][k].second;
break;
}
}
if(edge != needed[i]) continue;
vector<int> r;
for(int i=0;i<tree.size();i++){
if(tree[i] == edge) continue;
r.push_back(tree[i]);
}
r.push_back(g[i][j].second);
int cur = count_common_roads(r);
v.push_back(make_pair(g[i][j].second,cur));
mx = max(mx,cur);
}
for(int i=0;i<v.size();i++) if(v[i].second == mx) ok[v[i].first] = true;
}
for(int i=0;i<u.size();i++) if(ok[i]) anss.push_back(i);
return anss;
}
Compilation message
simurgh.cpp: In function 'void DFS(int, int)':
simurgh.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[node].size();i++){
^
simurgh.cpp: In function 'bool DFS2(int, int, int)':
simurgh.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<T[node].size();i++){
^
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<u.size();i++){
^
simurgh.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<g[i].size();j++){
^
simurgh.cpp:49:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<T[i].size();k++){
^
simurgh.cpp:58:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree.size();i++){
^
simurgh.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++) if(v[i].second == mx) ok[v[i].first] = true;
^
simurgh.cpp:69:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<u.size();i++) if(ok[i]) anss.push_back(i);
^
simurgh.cpp:42:6: warning: unused variable 'res' [-Wunused-variable]
int res = count_common_roads(tree);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2296 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2296 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2296 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2296 KB |
correct |
2 |
Incorrect |
0 ms |
2296 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2296 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |