제출 #436913

#제출 시각아이디문제언어결과실행 시간메모리
436913PiejanVDC열쇠 (IOI21_keys)C++17
컴파일 에러
0 ms0 KiB
#include "keys.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
    int n = r.size(), m = u.size();
    vector<pair<int,int>>adj[n];
    for(int i = 0 ; i < m ; i++) {
        adj[u[i]].push_back({v[i],i});
        adj[v[i]].push_back({u[i],i});
    }
    int mn=INT_MAX;
    vector<int>mini;
    vector<vector<bool>>vis(n,vector<bool>(n,false));
    for(int i = 0 ; i < n ; i++) {
        vector<bool>keys(n,false)
        queue<int>q;
        q.push(i);
        bool change=true;
        while(change) {
            change=false;
            int sz = q.size();
            while(sz--) {
                int node = q.front();
                q.pop();
                keys[r[node]]=true;
                restore.push_back(node);
                if(!vis[i][node]) {
                    for(int j = 0 ; j < n ; j++) {
                        if(vis[node][j]) {
                            vis[i][j]=true;
                            keys[r[j]]=true;
                        }
                    }
                    vis[i][node]=true;
                }
                for(auto z : adj[node]) {
                    if(keys[c[z.second]] && !vis[i][z.first]) {
                        change=true;
                        q.push(z.first);
                    }
                }
            }
         for(auto z : restore) q.push(z);
        }
    }
    
     if(curr < mn) {
        mini.clear();
        mini.push_back(i);
        mn=curr;
     } else if(curr == mn) mini.push_back(i);
    }
    vector<int>ans(n,0);
    for(auto z : mini) ans[z]=1;
    return ans;
}

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

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:17:9: error: expected ',' or ';' before 'queue'
   17 |         queue<int>q;
      |         ^~~~~
keys.cpp:18:9: error: 'q' was not declared in this scope
   18 |         q.push(i);
      |         ^
keys.cpp:27:17: error: 'restore' was not declared in this scope
   27 |                 restore.push_back(node);
      |                 ^~~~~~~
keys.cpp:44:23: error: 'restore' was not declared in this scope
   44 |          for(auto z : restore) q.push(z);
      |                       ^~~~~~~
keys.cpp:48:9: error: 'curr' was not declared in this scope
   48 |      if(curr < mn) {
      |         ^~~~
keys.cpp:50:24: error: 'i' was not declared in this scope
   50 |         mini.push_back(i);
      |                        ^
keys.cpp:52:43: error: 'i' was not declared in this scope
   52 |      } else if(curr == mn) mini.push_back(i);
      |                                           ^
keys.cpp:53:5: warning: no return statement in function returning non-void [-Wreturn-type]
   53 |     }
      |     ^
keys.cpp: At global scope:
keys.cpp:54:20: error: 'n' was not declared in this scope; did you mean 'yn'?
   54 |     vector<int>ans(n,0);
      |                    ^
      |                    yn
keys.cpp:55:5: error: expected unqualified-id before 'for'
   55 |     for(auto z : mini) ans[z]=1;
      |     ^~~
keys.cpp:56:5: error: expected unqualified-id before 'return'
   56 |     return ans;
      |     ^~~~~~
keys.cpp:57:1: error: expected declaration before '}' token
   57 | }
      | ^