제출 #1221159

#제출 시각아이디문제언어결과실행 시간메모리
1221159hmms127슈퍼트리 잇기 (IOI20_supertrees)C++20
컴파일 에러
0 ms0 KiB
#include "supertrees.h"
#include <vector>
using namespace std;
int frq[1005];
struct DSU{
  vector<int>par,sz;
  void init(int n){
      par.resize(n+1);sz.resize(n+1);
      for(int i=0;i<n;i++)par[i]=i,sz[i]=1;
  }  
  int root(int u){
      return par[u]==u ? u:par[u]=root(par[u]);
  }
  bool merge(int u,int v){
      int ru=root(u),rv=root(v);
      frq[u]++;
      frq[v]++;
      if(ru==rv)return 0;
      if(sz[ru]>sz[rv])swap(sz[ru],sz[rv]);
      par[ru]=rv;sz[rv]+=sz[ru];
      return 1;
  }
};
int dfs(int node,int target,vector<vector<int>>& adj,vector<bool>& visited) {
    if(u==target)return 1;
    visited[u]=true;
    int paths=0;
    for (int v:adj[u]) {
        if (!visited[v])paths+=countPaths(v, target, adj, visited);
    }
    visited[u] = false; 
    return paths;
}
int construct(std::vector<std::vector<int>> p) {
	int n=p[0].size();
    vector<vector<int>>v(n,vector<int>(n,0));
    DSU d,d1;d.init(n);d1.init(n);
    vector<int>adj[n];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
        if(i==j)continue;
        if(p[i][j]){
            if(d.root(i)==d.root(j)){d1.merge(i,j);}
            else d.merge(i,j);
            v[i][j]=1;
            v[j][i]=1;
            adj[i].pb(j);adj[j].pb(i);
        }
        }
    }
     for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
         if(p[i][j]==0&&d.root(i)==d.root(j))return 0;
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            vector<int> v(n,0);
            if(p[i][j]==2&&dfs(i,j,adj,vis)!=2)return 0;
        }
    }
	build(v);
	return 1;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int dfs(int, int, std::vector<std::vector<int> >&, std::vector<bool>&)':
supertrees.cpp:25:8: error: 'u' was not declared in this scope
   25 |     if(u==target)return 1;
      |        ^
supertrees.cpp:26:13: error: 'u' was not declared in this scope
   26 |     visited[u]=true;
      |             ^
supertrees.cpp:29:32: error: 'countPaths' was not declared in this scope
   29 |         if (!visited[v])paths+=countPaths(v, target, adj, visited);
      |                                ^~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:20: error: 'class std::vector<int>' has no member named 'pb'
   47 |             adj[i].pb(j);adj[j].pb(i);
      |                    ^~
supertrees.cpp:47:33: error: 'class std::vector<int>' has no member named 'pb'
   47 |             adj[i].pb(j);adj[j].pb(i);
      |                                 ^~
supertrees.cpp:60:40: error: 'vis' was not declared in this scope
   60 |             if(p[i][j]==2&&dfs(i,j,adj,vis)!=2)return 0;
      |                                        ^~~