제출 #398529

#제출 시각아이디문제언어결과실행 시간메모리
398529priority_queue슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
1 ms292 KiB
// ioi 2020, day 1, supertrees

#include <bits/stdc++.h>

using namespace std;

#define forint(i, N) for (int i = 0; i < (N); i++)

using namespace std;

void build(std::vector<std::vector<int> > b);

int construct(vector<std::vector<int> > p) {

	int N = p.size();

	vector< vector<int> > b(N, vector<int>(N, 0));

	vector<bool> visited(N, false);

	vector<std::vector<int> > p2(N, vector<int>(N, 0));

	forint(i, N) {

        if (!visited[i]) { // create new. All connected to i also not visited
            
            visited[i] = true;
        	
        	vector< vector<int> > circle(1);
			circle[0].push_back(i);
	
        	vector<int> path2 = {};
            
        	for (int j = i+1; j < N; j++) {
        		
        		if (p[i][j] == 1) {
        			if (visited[j]) {
        				return 0;
        			}
        			b[i][j] = 1;
        			b[j][i] = 1;
        			visited[j] = true;

        			circle[0].push_back(j);
//cerr << "he -->" << circle[0].size() << endl;
        			continue;
        		}

        		if (p[i][j] == 2) {
        			if (visited[j]) {
        				return 0;
        			}
        			path2.push_back(j);
        			continue;
        		}

        		if (p[i][j] == 3) {
        			return 0;
        		}
        	}

        	if (!path2.empty()) {
        		if (path2.size() < 2) {
        			return 0;
        		}

        		int last = i;

        		forint(j, path2.size()) {

        			if (!visited[path2[j]]) {
                		// make it root
        				b[last][path2[j]] = 1;
        				b[path2[j]][last] = 1;
        				last = path2[j];
        				visited[path2[j]] = true;

        				circle.push_back({path2[j]});

        				for (int j2 = j+1; j2 < path2.size(); j2++) {
        					if (!visited[path2[j2]] && p[path2[j]][path2[j2]] == 1) {
        						b[path2[j]][path2[j2]] = 1;
        						b[path2[j2]][path2[j]] = 1;
        						visited[path2[j2]] = true;

        						circle[circle.size()-1].push_back(path2[j2]);
        					}	
        				}
        			}
        		}
        		b[i][last] = 1;
        		b[last][i] = 1;
        	}

        	for (auto& c : circle) {
        		for (auto d : c) {
        			cout << d << " ";
        		}
        		cout << endl;
        	}

        	forint(c, circle.size()) {
        		for (int d1 = 0; d1 < circle[c].size(); d1++) {
        			for (int d2 = 0; d2 < circle[c].size(); d2++) {
        				p2[circle[c][d1]][circle[c][d2]] = 1;
        			}	
        		}

        		forint(d, circle.size()) {
        			if (c!=d) {
		        		for (int d1 = 0; d1 < circle[c].size(); d1++) {
        					for (int d2 = 0; d2 < circle[d].size(); d2++) {
        						p2[circle[c][d1]][circle[d][d2]] = 2;
	        				}	
    		    		}
        			}
        		}
        	}
        }
    }

    forint(i, N) {
    	forint(j, N) {
    		if (p2[i][j] != p[i][j]) {
    			return 0;
    		}
    	}
    }
    
    build(b);

    return 1;

}

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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:7:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forint(i, N) for (int i = 0; i < (N); i++)
      |                                        ^
supertrees.cpp:69:11: note: in expansion of macro 'forint'
   69 |           forint(j, path2.size()) {
      |           ^~~~~~
supertrees.cpp:80:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             for (int j2 = j+1; j2 < path2.size(); j2++) {
      |                                ~~~^~~~~~~~~~~~~~
supertrees.cpp:7:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forint(i, N) for (int i = 0; i < (N); i++)
      |                                        ^
supertrees.cpp:102:10: note: in expansion of macro 'forint'
  102 |          forint(c, circle.size()) {
      |          ^~~~~~
supertrees.cpp:103:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |           for (int d1 = 0; d1 < circle[c].size(); d1++) {
      |                            ~~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:104:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |            for (int d2 = 0; d2 < circle[c].size(); d2++) {
      |                             ~~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:7:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forint(i, N) for (int i = 0; i < (N); i++)
      |                                        ^
supertrees.cpp:109:11: note: in expansion of macro 'forint'
  109 |           forint(d, circle.size()) {
      |           ^~~~~~
supertrees.cpp:111:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |             for (int d1 = 0; d1 < circle[c].size(); d1++) {
      |                              ~~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:112:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |              for (int d2 = 0; d2 < circle[d].size(); d2++) {
      |                               ~~~^~~~~~~~~~~~~~~~~~
#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...