답안 #868658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868658 2023-11-01T07:20:23 Z abcvuitunggio 열쇠 (IOI21_keys) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
vector <int> ke[300001],res;
int n,m,isInStack[300001],low[300001],idx[300001],R[300001],cnt[300001],ch[300001],index=1,mn=1e9;
stack <int> s;
void ssc(int v){
    idx[v]=index;
    low[v]=index;
    index++;
    s.push(v);
    isInStack[v]=1;
    for (int w:ke[v]){
        if (idx[w]==0){
            ssc(w);
            low[v]=min(low[w],low[v]);
        }
        else if (isInStack[w])
            low[v]=min(low[v],idx[w]);
    }
    if (low[v]==idx[v]){
        while (s.top()!=v){
            isInStack[s.top()]=false;
            R[s.top()]=v;
            cnt[v]++;
            s.pop();
        }
        isInStack[v]=false;
        cnt[v]++;
        s.pop();
    }
}
void tarjan(){
    iota(R,R+n,0);
    for (int i=0;i<n;i++)
        if (idx[i]==0)
            ssc(i);
}
vector <int> find_reachable(vector <int> r, vector <int> u, vector <int> v, vector <int> c){
    n=r.size();
    m=u.size();
    for (int i=0;i<m;i++){
        if (r[u[i]]==c[i])
            ke[u[i]].push_back(v[i]);
        if (r[v[i]]==c[i])
            ke[v[i]].push_back(u[i]);
    }
    tarjan();
    for (int i=0;i<n;i++)
        for (int j:ke[i])
            if (R[j]!=R[i])
                ch[R[i]]=1;
    for (int i=0;i<n;i++)
        if (i==R[i]&&!ch[i])
            mn=min(mn,cnt[i]);
    for (int i=0;i<n;i++)
        res.push_back(!ch[R[i]]&&cnt[R[i]]==mn);
	return res;
}

Compilation message

keys.cpp:4:84: error: 'int index' redeclared as different kind of entity
    4 | int n,m,isInStack[300001],low[300001],idx[300001],R[300001],cnt[300001],ch[300001],index=1,mn=1e9;
      |                                                                                    ^~~~~
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from keys.cpp:1:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
keys.cpp: In function 'void ssc(int)':
keys.cpp:7:12: error: cannot resolve overloaded function 'index' based on conversion to type 'int'
    7 |     idx[v]=index;
      |            ^~~~~
keys.cpp:8:12: error: cannot resolve overloaded function 'index' based on conversion to type 'int'
    8 |     low[v]=index;
      |            ^~~~~
keys.cpp:9:10: error: no post-increment operator for type
    9 |     index++;
      |          ^~
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:55:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   55 |     for (int i=0;i<n;i++)
      |     ^~~
keys.cpp:57:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   57 |  return res;
      |  ^~~~~~