帮看一下程序结果对不对谢谢
查看原帖
帮看一下程序结果对不对谢谢
347174
lnwwr楼主2020/9/8 21:30

程序DFS全部RE了,优化我会自己搞,仅求各位神犇看看思路和结果对不对。我知道BFS不超时但是我就是太闲了

#include <iostream>
  
using namespace std;
  
int c[2005][2005];
  
int cnt[2005];
  
int ord[2005];
  
int n , m , q;
  
bool dfs(int Lev , int place);
  
int main() {
  
    cin >> n >> m >> q;
  
    for(int i = 1; i <= m; i++) {
                         
        int u , v;
                         
        c[u][cnt[u]] = v;
                         
        cnt[u]++;
                         
    }
                         
    for(int i = 1; i <= q; i++) {
  
        int a , L;
  
        cin >> a >> L;
  
        ord[a] = L;
  
        bool tempans;
  
        tempans = dfs(ord[a] , a);
  
        if(tempans == true) {
  
            cout << "Yes" << endl;
  
            continue;
  
        }
  
        cout << "No" << endl;
  
    }
  
    return 0;
  
}
  
bool dfs(int Lev , int place) {
  
    if(Lev == 0) return false;
  
    for(int i = 1; i < cnt[place]; i++) {
                                  
        if(Lev == 1) {
                                  
            for(int j = 1; j < cnt[place]; j++) {
  
                if(j == 1) {
  
                    return true;
  
                }
  
            }
  
        } else {
  
            dfs(Lev - 1 , i);
  
        }
  
    }
  
}
2020/9/8 21:30
加载中...