Submission #977456

#TimeUsernameProblemLanguageResultExecution timeMemory
977456AmaarsaaConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "supertrees.h" using namespace std; vector < int > adj[1002]; int ataman[10002], used[1002]; int Get(int x) { if ( x == ataman[x]) return x; return ataman[x] = Get(ataman[x]); } void Unite(int x, int y) { x = Get(x); y = Get(y); if (x == y) return ; if ( x < y) swap(x, y); ataman[x]= y; } void build(vector<vector<int>> a) { for (int i = 0; i < a.size(); i ++) { for (int j = 0; j < a[i].size(); j ++) { if ( a[i][j] == 1) { cout << i << " " << j << endl; } } } } int construct(vector<vector<int>> a) { int n = a.size(), i, j; vector < vector < int > > ans(n, vector<int>(n, 0)); for (i = 0; i < n; i ++) ataman[i]= i; int s = 1; for ( i = 0; i < n; i++) { for ( j = 0; j < n; j ++) { if ( a[i][j] == 1 && i != j) Unite(i, j); } } for (i = 0; i < n; i ++) ataman[i] = i; for (i = 0; i < n; i ++) { for (j = 0; j < n; j ++) { if ( a[i][j] == 2 && i != j) Unite(i, j); } } for (i = 0; i < n; i ++) used[i] = 0; for (i = 0; i < n; i ++) { for (j = 0; j < n; j ++) { if ( i == j) continue; if ( (a[i][j] == 0 || a[i][j] == 3) && Get(i) == Get(j)) s= 0; if ( a[i][j] == 2 && Get(i) != Get(j)) s = 0; } } for (i = 0; i < n; i ++) { vector < int > v; v.push_back(i); for (j = i + 1; j < n; j ++) { if ( Get(j) == Get(i) && !used[j]) v.push_back(j); } if(v.size() == 1) continue; if ( v.size() == 2){ s = 0; break; } used[i] = 1; for (j = 1; j < v.size(); j ++) { used[v[j]] = 1; ans[v[j]][v[j - 1]] = ans[v[j - 1]][v[j]] = 1; } ans[v[0]][v[v.size() -1]] = ans[v[v.size() -1]][v[0]] = 1; } for (i = 0; i < n; i ++) { for (j = 0; j < n; j ++) { if ( i == j) continue; if ( (a[i][j] == 0 || a[i][j] == 3) && Get(i) == Get(j)) s= 0; if ( a[i][j] == 1 && Get(i) != Get(j)) s = 0; } } for (i = 0; i < n; i ++) { vector < int > v; v.push_back(i); for (j = i + 1; j < n; j ++) { if ( Get(j) == Get(i) && !used[j]) v.push_back(j); } used[i] = 1; for (j = 1; j < v.size(); j ++) { used[v[j]] = 1; ans[v[j]][v[j - 1]] = ans[v[j - 1]][v[j]] = 1; } } if ( s == 0) return 0; build(ans); return s; }

Compilation message (stderr)

supertrees.cpp: In function 'void build(std::vector<std::vector<int> >)':
supertrees.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (int i = 0; i < a.size(); i ++) {
      |                  ~~^~~~~~~~~~
supertrees.cpp:19:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   for (int j = 0; j < a[i].size(); j ++) {
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:63:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (j = 1; j < v.size(); j ++) {
      |               ~~^~~~~~~~~~
supertrees.cpp:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for (j = 1; j < v.size(); j ++) {
      |               ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccT264U3.o: in function `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
grader.cpp:(.text+0x320): multiple definition of `build(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'; /tmp/ccYKe3O2.o:supertrees.cpp:(.text+0x1d0): first defined here
collect2: error: ld returned 1 exit status