제출 #437663

#제출 시각아이디문제언어결과실행 시간메모리
437663xiaowuc1슈퍼트리 잇기 (IOI20_supertrees)C++17
21 / 100
261 ms24184 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <vector> #include "supertrees.h" using namespace std; // BEGIN NO SAD #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound typedef vector<int> vi; #define f first #define s second // END NO SAD typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<vector<ll>> matrix; int find(vector<int>& p, int x) { return p[x] == x ? x : (p[x] = find(p, p[x])); } void merge(vector<int>& p, int x, int y) { p[find(p, x)] = find(p, y); } int construct(vector<vector<int>> p) { int n = sz(p); vector<vector<int>> ret; for(int i = 0; i < n; i++) { vector<int> t(n); ret.pb(t); } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 3) return 0; vector<int> connectedcomponent(n); iota(all(connectedcomponent), 0); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j]) merge(connectedcomponent, i, j); // check zero for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 0 && find(connectedcomponent, i) == find(connectedcomponent, j)) return 0; // check one vector<int> oneedge(n); iota(all(oneedge), 0); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 1) merge(oneedge, i, j); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { if(p[i][j] == 0) continue; if(p[i][j] != 1 && find(oneedge, i) != find(oneedge, j)) return 0; } map<int, int> treetoroot; for(int i = 0; i < n; i++) { if(!treetoroot.count(find(oneedge, i))) { treetoroot[find(oneedge, i)] = i; } else { ret[treetoroot[find(oneedge, i)]][i] = 1; ret[i][treetoroot[find(oneedge, i)]] = 1; } } map<int, set<int>> roots; for(int i = 0; i < n; i++) { roots[find(connectedcomponent, i)].insert(treetoroot[find(oneedge, i)]); } for(auto out: roots) { cerr << out.f << " has roots:"; for(auto out2: out.s) cerr << " " << out2; cerr << endl; if(sz(out.s) == 2) return 0; if(sz(out.s) == 1) continue; vector<int> v(all(out.s)); for(int i = 0; i < sz(v); i++) { int j = (i+1)%sz(v); ret[v[i]][v[j]] = 1; ret[v[j]][v[i]] = 1; } } build(ret); return 1; }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:83:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   83 |   for(auto out2: out.s) cerr << " " << out2; cerr << endl;
      |   ^~~
supertrees.cpp:83:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   83 |   for(auto out2: out.s) cerr << " " << out2; cerr << endl;
      |                                              ^~~~
#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...