QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568090#9310. Permutation Counting 4flysky701Compile Error//C++17975b2024-09-16 15:12:212024-09-16 15:12:22

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 14:56:40]
  • hack成功,自动添加数据
  • (/hack/835)
  • [2024-09-18 14:41:06]
  • hack成功,自动添加数据
  • (/hack/831)
  • [2024-09-17 12:14:52]
  • hack成功,自动添加数据
  • (/hack/825)
  • [2024-09-16 15:12:22]
  • 评测
  • [2024-09-16 15:12:21]
  • 提交

answer

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
using namespace std;


typedef pair<int, int> PII;

vector<int> f;
int find(int x){
    if(f[x] != x)
        return f[x] = find(f[x]);
    return f[x];
}
bool merge(int u, int v){
    int u = find(u), v = find(v);
    if(u == v)return false;
    f[v] = u;
}

    void solve()
{
    int n;
    cin >> n;
    f.assign(n + 10, 0);

    vector<PII> eg(n + 10);
    for (int i = 1; i <= n; i ++){
        auto &[l, r] = eg[i];
        cin >> l >> r;
        l--;
        f[i] = i;
    }

    int ok = 1;
    for (int i = 1; i <= n; i ++){
        auto [l, r] = eg[i];
        if (merge(l, r) == false){
            ok = 0;
            break;
        }
    }

    if(ok){
        cout << 0 << endl;
    }else
        cout << 1 << endl;
}
signed main(){
    ios;
    int T;
    cin >> T;

    while(T --)
        solve();
}

詳細信息

answer.code: In function ‘bool merge(int, int)’:
answer.code:16:9: error: declaration of ‘int u’ shadows a parameter
   16 |     int u = find(u), v = find(v);
      |         ^
answer.code:15:16: note: ‘int u’ previously declared here
   15 | bool merge(int u, int v){
      |            ~~~~^
answer.code:16:22: error: declaration of ‘int v’ shadows a parameter
   16 |     int u = find(u), v = find(v);
      |                      ^
answer.code:15:23: note: ‘int v’ previously declared here
   15 | bool merge(int u, int v){
      |                   ~~~~^
answer.code:18:10: warning: control reaches end of non-void function [-Wreturn-type]
   18 |     f[v] = u;