제출 #303131

#제출 시각아이디문제언어결과실행 시간메모리
303131qpwoeirut슈퍼트리 잇기 (IOI20_supertrees)C++17
0 / 100
1 ms384 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> vvi; typedef pair<int,int> pii; const int MN = 1001; int N; int root[MN]; int par(int u) { if (u == root[u]) return u; root[u] = par(root[u]); return root[u]; } void join(int u, int v) { int ru = par(u), rv = par(v); if (ru == rv) return; root[ru] = rv; } bool dsu(const vvi& p) { for (int i=0; i<N; ++i) { root[i] = i; } for (int i=0; i<N; ++i) { for (int j=0; j<N; ++j) { if (p[i][j] == 3) return 0; if (p[i][j]) join(i, j); } } for (int i=0; i<N; ++i) { for (int j=0; j<N; ++j) { if (p[i][j] == 0 && par(i) == par(j)) return 0; } } return 1; } int ones[MN]; vvi ans; bool make_part(const vvi& p, const vector<int>& nodes) { set<pii, greater<pii>> q; for (int i=0; i<nodes.size(); ++i) { q.insert(pii(ones[nodes[i]], nodes[i])); } int root = -1; int last = -1; while (q.size() > 0) { int cur = q.begin()->second; q.erase(q.begin()); if (root == -1) { root = cur; } if (last != -1) { ans[cur][last] = 1; ans[last][cur] = 1; } last = cur; for (int i=0; i<N; ++i) { if (p[cur][i] == 1) { if (ones[i] != 1) { return false; } ans[cur][i] = 1; ans[i][cur] = 1; q.erase(pii(ones[i], i)); } } } return 1; } int construct(std::vector<std::vector<int>> p) { N = p.size(); if (!dsu(p)) return 0; map<int, vector<int>> parts; for (int i=0; i<N; ++i) { parts[par(i)].push_back(i); for (int j=0; j<N; ++j) { if (p[i][j] == 1) ++ones[i]; } } ans = vvi(N, vector<int>(N)); for (auto it=parts.begin(); it!=parts.end(); ++it) { if (!make_part(p, it->second)) return 0; } build(ans); return 1; }

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

supertrees.cpp: In function 'bool make_part(const vvi&, const std::vector<int>&)':
supertrees.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i=0; i<nodes.size(); ++i) {
      |                   ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...