Submission #1004751

# Submission time Handle Problem Language Result Execution time Memory
1004751 2024-06-21T13:39:31 Z spensa Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
513 ms 69016 KB
#include "supertrees.h"
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

int construct(std::vector<std::vector<int>> p) {
    //subtask 3: mini cycles, but as connected components
	int n = p.size();
    vector<vector<int>> ans(n, vector<int> (n));  

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            ans[i][j] = 0;
        }
    }

    map<int, vector<int>> cc;
    vector<int> flags;
    flags.push_back(0);
    cc[0].push_back(0);
    for(int i=1; i<n; i++){
        int tmp = 0;
        for(int j: flags){
            if(p[i][j]==0) continue;
            if(i==j) continue;
            // ans[i][j] = 1;
            // ans[j][i] = 1;
            cc[j].push_back(i);
            tmp++;
            // break;
        }
        if(tmp>=2) return 0;
        if(tmp==0){
            flags.push_back(i);
            cc[i].push_back(i);
        }
    }

    for(auto i: cc){
        // cout<<i.first<<"!";
        // for(int j: i.second) cout<<j<<" ";
        // cout<<"\n";
        int sz = i.second.size();
        // cout<<sz<<"\n";
        if(sz==0 || sz==1) continue;
        if(sz==2) return 0;
        for(int j=1; j<sz; j++){
            ans[i.second[j]][i.second[j-1]] = 1;
            ans[i.second[j-1]][i.second[j]] = 1;
        }
        ans[i.second[0]][i.second[sz-1]] = 1;
        ans[i.second[sz-1]][i.second[0]] = 1;
    }

    set<pair<int,int>> act;
    for(auto i: cc){
        // cout<<"i.first="<<i.first<<"\n";
        for(int j: i.second){
            for(int k: i.second){
                act.insert(make_pair(j, k));
                act.insert(make_pair(k, j));
            }
        }
    }

    // for(auto i: act) cout<<i.first<<" "<<i.second<<"\n";
    // cout<<"\n";

    // sort(act.begin(), act.end());
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            // cout<<"here";
            if(i==j) continue;
            if(p[i][j]==0){
                if(act.count({i,j})==1) return 0;
            }
            else{
                if(act.count({i,j})==0) return 0;
            }
        }
    }

    build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 121 ms 22096 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 14 ms 3164 KB Output is correct
13 Correct 513 ms 69016 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 49 ms 12056 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 34 ms 6036 KB Output is correct
22 Correct 152 ms 28800 KB Output is correct
23 Correct 116 ms 24400 KB Output is correct
24 Correct 294 ms 47444 KB Output is correct
25 Correct 48 ms 14164 KB Output is correct
26 Correct 74 ms 18932 KB Output is correct
27 Correct 134 ms 24400 KB Output is correct
28 Correct 297 ms 47440 KB Output is correct
29 Correct 55 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -