제출 #417409

#제출 시각아이디문제언어결과실행 시간메모리
417409ioi슈퍼트리 잇기 (IOI20_supertrees)C++14
11 / 100
322 ms30112 KiB
#include "supertrees.h" #include <vector> #include<bits/stdc++.h> using namespace std ; const int N = 1002; int dsu[N] , sz[N]; int get(int u){ if(u == dsu[u]) return u ; return dsu[u] = get(dsu[u]); } void connect(int u , int v){ u = get(u) , v = get(v); if(u == v)return ; if(sz[u] > sz[v])swap(u , v); sz[v] += sz[u]; dsu[u] = v ; } bool same(int u , int v){ u = get(u) , v = get(v); return u == v ; } vector<int> v , adj[N]; int vis[N] , vid ; void dfs(int u){ vis[u] = vid ; v.push_back(u); for(auto f : adj[u]){ if(vis[f] != vid)dfs(f); } } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer (n , vector<int> (n , 0)); for(int i = 0 ; i < n ; i ++)sz[i] = 1 , dsu[i] = i ; int cnt[n] = {} , cnt1[n] = {}; for(int i = 0 ; i < n ; i ++){ for(int j = 0 ; j < n ; j ++){ if(p[i][j])connect(i , j); if(i == j)continue; cnt[i] += (p[i][j] == 2 );cnt1[i] += (p[i][j] == 1); if(p[i][j] == 1 && i != j)adj[i].push_back(j) , adj[j].push_back(i); } } map<int, set<int> > mp ; for(int i = 0 ; i < n ; i ++){ for(int j = 0 ; j < n ;j ++) { // if(p[i][j] == 0&& same(i , j) || (p[i][j] && sz[get(dsu[i])] == 2))return 0 ; if(p[i][j] && i != j)mp[dsu[i]].insert(i) , mp[dsu[i]].insert(j); } } for(auto f : mp){ vector<int> els , iif; int sz = f.second.size(); int flag = 0 ; for(auto ff : f.second){ if(cnt[ff] == sz - 1) iif.push_back(ff); else if(!flag && cnt[ff]){ flag ++ ; iif.push_back(ff); } else els.push_back(ff); } if(iif.size()){ int past = iif[0]; for(int i = 1 ; i < iif.size() ; i ++){ int curr = iif[i]; answer[curr][past] = answer[past][curr] =1 ; past = curr ; } answer[iif[0]][past] = answer[past][iif[0]] = 1 ; vid ++ ; for(auto ff : iif){ v.clear(); dfs(ff); if(v.size()){ int past = ff ; for(int i = 1 ; i < v.size() ; i ++){ int curr = v[i]; answer[curr][past] = answer[past][curr] = 1 ; past = curr ; } } } } else if(els.size()){ int past = els[0]; for(int i = 1 ; i < els.size(); i ++){ int curr = els[i]; answer[curr][past] = answer[past][curr] = 1 ; past = curr ; } } } for(int i = 0 ; i < n ; i ++)answer[i][i] = 0 ; build(answer); return 1; }

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:100:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |             for(int i = 1 ; i < iif.size() ; i ++){
      |                             ~~^~~~~~~~~~~~
supertrees.cpp:117:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |                     for(int i = 1 ; i < v.size() ; i ++){
      |                                     ~~^~~~~~~~~~
supertrees.cpp:134:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |             for(int i = 1 ; i < els.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...