#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> >adj[501];
vector<int>t;
vector<int> res;
bool vis[501], check[125000]={false} ;
int N;
void DFS(int u, int p){
vis[u]=true;
for(auto v:adj[u]){
if(v.first!=p && vis[v.first]==false){
if(p!=-1) t.push_back(v.second);
DFS(v.first, u);
}
}
}
int calc(int u){
vector<int>b;
int mx=-1, p=-1, tmp;
if(t.size()!=N-2) return -1;
for(auto v:adj[u]){
if(check[v.second]){
t.push_back(v.second);
mx=count_common_roads(t);
t.pop_back();
break;
}
}
for(auto v:adj[u]){
if(check[v.second])continue;
t.push_back(v.second);
tmp=count_common_roads(t);
if(mx==-1){
mx=tmp;
b.push_back(v.second);
p=v.second;
}
else if(tmp>mx){
b.clear();
mx=tmp;
b.push_back(v.second);
p=v.second;
}
else if(tmp==mx){
b.push_back(v.second);
p=v.second;
}
t.pop_back();
}
for(int i=0; i<b.size(); i++){
check[b[i]]=true;
res.push_back(b[i]);
}
return p;
}
vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
N=n;
int f, ind=0;
memset(check, false, sizeof check);
for(int i=0; i<u.size(); i++){
adj[u[i]].push_back({v[i], i});
adj[v[i]].push_back({u[i], i});
}
if(u.size()==n-1){
for(int i=0; i<n-1; i++) res.push_back(i);
return res;
}
for(int i=0; i<n; i++){
memset(vis, false, sizeof vis);
t.clear();
DFS(i, -1);
f=calc(i);
if(f<0 || f>u.size() || check[f]) continue;
}
res.resize(n-1);
return res;
}
Compilation message
simurgh.cpp: In function 'int calc(int)':
simurgh.cpp:25:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(t.size()!=N-2) return -1;
~~~~~~~~^~~~~
simurgh.cpp:55:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<b.size(); i++){
~^~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:66:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<u.size(); i++){
~^~~~~~~~~
simurgh.cpp:70:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(u.size()==n-1){
~~~~~~~~^~~~~
simurgh.cpp:79:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(f<0 || f>u.size() || check[f]) continue;
~^~~~~~~~~
simurgh.cpp:64:9: warning: unused variable 'ind' [-Wunused-variable]
int f, ind=0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
correct |
2 |
Correct |
3 ms |
616 KB |
correct |
3 |
Correct |
2 ms |
616 KB |
correct |
4 |
Correct |
4 ms |
616 KB |
correct |
5 |
Correct |
3 ms |
616 KB |
correct |
6 |
Correct |
4 ms |
616 KB |
correct |
7 |
Correct |
3 ms |
748 KB |
correct |
8 |
Correct |
3 ms |
748 KB |
correct |
9 |
Correct |
4 ms |
748 KB |
correct |
10 |
Correct |
4 ms |
748 KB |
correct |
11 |
Correct |
3 ms |
748 KB |
correct |
12 |
Correct |
3 ms |
748 KB |
correct |
13 |
Correct |
3 ms |
752 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
correct |
2 |
Correct |
3 ms |
616 KB |
correct |
3 |
Correct |
2 ms |
616 KB |
correct |
4 |
Correct |
4 ms |
616 KB |
correct |
5 |
Correct |
3 ms |
616 KB |
correct |
6 |
Correct |
4 ms |
616 KB |
correct |
7 |
Correct |
3 ms |
748 KB |
correct |
8 |
Correct |
3 ms |
748 KB |
correct |
9 |
Correct |
4 ms |
748 KB |
correct |
10 |
Correct |
4 ms |
748 KB |
correct |
11 |
Correct |
3 ms |
748 KB |
correct |
12 |
Correct |
3 ms |
748 KB |
correct |
13 |
Correct |
3 ms |
752 KB |
correct |
14 |
Correct |
7 ms |
788 KB |
correct |
15 |
Correct |
5 ms |
796 KB |
correct |
16 |
Correct |
6 ms |
948 KB |
correct |
17 |
Correct |
6 ms |
948 KB |
correct |
18 |
Correct |
5 ms |
948 KB |
correct |
19 |
Correct |
6 ms |
948 KB |
correct |
20 |
Correct |
5 ms |
948 KB |
correct |
21 |
Correct |
6 ms |
948 KB |
correct |
22 |
Incorrect |
5 ms |
948 KB |
WA in grader: NO |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
correct |
2 |
Correct |
3 ms |
616 KB |
correct |
3 |
Correct |
2 ms |
616 KB |
correct |
4 |
Correct |
4 ms |
616 KB |
correct |
5 |
Correct |
3 ms |
616 KB |
correct |
6 |
Correct |
4 ms |
616 KB |
correct |
7 |
Correct |
3 ms |
748 KB |
correct |
8 |
Correct |
3 ms |
748 KB |
correct |
9 |
Correct |
4 ms |
748 KB |
correct |
10 |
Correct |
4 ms |
748 KB |
correct |
11 |
Correct |
3 ms |
748 KB |
correct |
12 |
Correct |
3 ms |
748 KB |
correct |
13 |
Correct |
3 ms |
752 KB |
correct |
14 |
Correct |
7 ms |
788 KB |
correct |
15 |
Correct |
5 ms |
796 KB |
correct |
16 |
Correct |
6 ms |
948 KB |
correct |
17 |
Correct |
6 ms |
948 KB |
correct |
18 |
Correct |
5 ms |
948 KB |
correct |
19 |
Correct |
6 ms |
948 KB |
correct |
20 |
Correct |
5 ms |
948 KB |
correct |
21 |
Correct |
6 ms |
948 KB |
correct |
22 |
Incorrect |
5 ms |
948 KB |
WA in grader: NO |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
948 KB |
correct |
2 |
Correct |
2 ms |
952 KB |
correct |
3 |
Incorrect |
125 ms |
3996 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
correct |
2 |
Correct |
3 ms |
616 KB |
correct |
3 |
Correct |
2 ms |
616 KB |
correct |
4 |
Correct |
4 ms |
616 KB |
correct |
5 |
Correct |
3 ms |
616 KB |
correct |
6 |
Correct |
4 ms |
616 KB |
correct |
7 |
Correct |
3 ms |
748 KB |
correct |
8 |
Correct |
3 ms |
748 KB |
correct |
9 |
Correct |
4 ms |
748 KB |
correct |
10 |
Correct |
4 ms |
748 KB |
correct |
11 |
Correct |
3 ms |
748 KB |
correct |
12 |
Correct |
3 ms |
748 KB |
correct |
13 |
Correct |
3 ms |
752 KB |
correct |
14 |
Correct |
7 ms |
788 KB |
correct |
15 |
Correct |
5 ms |
796 KB |
correct |
16 |
Correct |
6 ms |
948 KB |
correct |
17 |
Correct |
6 ms |
948 KB |
correct |
18 |
Correct |
5 ms |
948 KB |
correct |
19 |
Correct |
6 ms |
948 KB |
correct |
20 |
Correct |
5 ms |
948 KB |
correct |
21 |
Correct |
6 ms |
948 KB |
correct |
22 |
Incorrect |
5 ms |
948 KB |
WA in grader: NO |
23 |
Halted |
0 ms |
0 KB |
- |