#include "simurgh.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
const int N = 2e5+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
int used[N], which[N], ue[N], ans, nn, mm;
vector<pii> edges[N];
vii qq;
void dfs_fix(int u){
used[u] = 1;
for(auto x:edges[u]){
if(used[x.ff]) continue;
which[x.ff] = x.ss;
ue[x.ss] = 1;
qq.pb(x.ss);
dfs_fix(x.ff);
}
}
vii res = {-1};
void dfs(int u){
if(res[0] != -1) return;
for(auto x:edges[u]){
int cur = x.ff, cost = x.ss;
if(ue[cost]) continue;
ue[cost] = 1;
int ff = which[cur];
ue[ff] = 0;
vii tmp;
for(int i=0;i<mm;i++){
if(ue[i]) tmp.pb(i);
}
int tt = count_common_roads(tmp);
if(tt == nn-1){
res = tmp;
return;
}
if(tt <= ans){
ue[ff] = 1;
ue[cost] = 0;
}else ans = tt;
}
for(auto x:edges[u]) if(res[0] == -1) dfs(x.ff);
}
vector<int> find_roads(int N, vector<int> u, vector<int> v) {
nn = N, mm = sz(u);
for(int i=0;i<sz(u);i++){
edges[u[i]].pb({v[i], i});
edges[v[i]].pb({u[i], i});
}
dfs_fix(0);
ans = count_common_roads(qq);
if(ans == nn-1) return qq;
dfs(0);
return res;
}
/*
5 7
0 1
0 2
1 2
2 3
2 4
3 4
1 4
0
1
3
5
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
5868 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
5868 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
5868 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4972 KB |
correct |
2 |
Incorrect |
3 ms |
4972 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
5868 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |