답안 #653697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653697 2022-10-27T17:37:33 Z Litusiano 슈퍼트리 잇기 (IOI20_supertrees) C++14
30 / 100
227 ms 28016 KB
#include "supertrees.h"
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define f first
#define s second
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vvii vector<vector<ii>>
#define pb push_back
#define vpi vector<ii> 
#define forcin for(int i = 0; i<n; ++i) cin>>v[i];
#define pq priority_queue<ii>
#define mp make_pair
#define ld long double
#define vc vector<char>
#define vvc vector<vc>
#define vb vector<bool>
#define vvb vector<vb>
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define For(i, n, x) for (int i = x; i < n; i++)
#define rsz(a,x) assign(a,x)
#define endl "\n"
 
int construct(vvi p){
  // Cap cami, components diferents
  // tots == 1, graf lineal
  // tots == 2, graf lineal amb el ultim unit al primer
  int N = p.size();
  bool ok = 0;
  For(i,N,0){
    ok|=(p[i][i] == 0);
  }
  if(ok) return 0;
  vvi used(N,vi(N,0));
  if(N == 1){
    if(p[0][0] == 1){
      build(used); return 1;
    }
    return 0;
  } 
  vpi edges;
  /*For(i,N,0){
    For(j,N,0) cout<<p[i][j]<<" "; cout<<endl;
  }*/
  for(auto x : p){
    for(auto e : x){
      if(e == 3) return 0;
    }
  }
  For(i,N,0){
    For(j,N,0){
      if(used[i][j] || i == j) continue;
      //cout<<p[i][j]<<" "<<j<<endl;
      if(p[i][j] == 0) continue;
      //cout<<i<<" "<<j<<endl;
      // si tinc 1, vaig buscant 1ns sino dosos
      int cur = j;
      set<int> act;
      edges.pb({i,j});
      act.insert(i);
      used[i][j] = used[j][i] = 1;
      // Miro TOT EL CICLE
      int last = j;
      int prev = i;
      while(!act.count(cur)){
        act.insert(j);
        bool b = false;
        int nextcur = i;
        For(k,N,0){
          //if(cur == j && k == i) continue;
          if(cur == k) continue;
          if(cur == 2){
            //cout<<"H"<<" "<<k<<" "<<act.count(k)<<" "<<used[cur][k]<<endl;
            //for(auto x : act) cout<<x<<" "; cout<<"ENDH"<<endl;
          }
          if(act.count(k) && cur != k){
            if(p[k][cur] != p[cur][k] || p[cur][k] != p[i][j]){
              //cout<<"HERE "<<cur<<" "<<k<<" "<<i<<" "<<j<<" "<<p[i][j]<<" "<<p[cur][k]<<endl;
              return 0;
            }
          }
          
          else if(!act.count(k) && p[cur][k] == p[i][j] && !used[cur][k] && !b){
            //cout<<i<<" "<<j<<" CUR "<<cur<<" "<<k<<endl;
            //for(auto x : act) cout<<x<<" "; cout<<endl;
            //act.insert(k);
            for(auto x : act){
              used[x][k] = used[k][x] = 1;
            }
            b = 1;
            //afegir edge
            edges.pb({cur,k});
            used[cur][k] = 1;
            used[k][cur] = 1;
            last = cur;
            nextcur = k;
          }
        }
        act.insert(cur);
        last = cur;
        cur = nextcur;
      }
      //cout<<i<<" "<<j<<endl;
      //for(auto x : act) cout<<x<<" "; cout<<endl;
      //cerr<<last<<" "<<i<<endl;
      if(p[i][j] == 2) edges.pb({last,i});
      if(act.size() <= 2 && p[i][j] == 2){
        //cerr<<i<<" "<<j<<" "<<endl;
        //for(auto x : act) cerr<<x<<" "; cerr<<endl;
        return 0;
      }
    }
  }
  //cout<<"AAAAA"<<endl;
  //cerr<<edges.size()<<endl;
  
  vvi ans(N,vi(N,0));
  if(!edges.size()){
    // 1 0 1 0 1 0 1 0 1 
    For(i,N,0){
      For(j,N,0){
        if(p[i][j] == 1 && i != j) return 0;
        if(p[i][j] == 2) return 0;
      }
    }
    build(ans); return 1;
  }
  sort(all(edges));
  for(auto x : edges){
    //if(ans[x.f][x.s]) return 0;
    ans[x.f][x.s] = ans[x.s][x.f] = 1;
    //cerr<<x.f<<" "<<x.s<<endl;
  }
  build(ans);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:72:11: warning: unused variable 'prev' [-Wunused-variable]
   72 |       int prev = i;
      |           ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1356 KB Output is correct
7 Correct 208 ms 26016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1356 KB Output is correct
7 Correct 208 ms 26016 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 11 ms 1236 KB Output is correct
13 Correct 196 ms 25976 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 11 ms 1360 KB Output is correct
9 Correct 202 ms 26008 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1316 KB Output is correct
13 Correct 210 ms 26000 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 97 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 47 ms 6756 KB Output is correct
22 Correct 194 ms 27876 KB Output is correct
23 Correct 176 ms 27852 KB Output is correct
24 Correct 227 ms 27884 KB Output is correct
25 Correct 72 ms 13948 KB Output is correct
26 Correct 73 ms 14044 KB Output is correct
27 Correct 186 ms 27872 KB Output is correct
28 Correct 214 ms 27852 KB Output is correct
29 Correct 79 ms 14028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 46 ms 7156 KB Output is correct
5 Correct 197 ms 28016 KB Output is correct
6 Correct 177 ms 27872 KB Output is correct
7 Correct 224 ms 27928 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 44 ms 7152 KB Output is correct
10 Correct 186 ms 27932 KB Output is correct
11 Correct 187 ms 27880 KB Output is correct
12 Correct 211 ms 27880 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1356 KB Output is correct
7 Correct 208 ms 26016 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 11 ms 1236 KB Output is correct
13 Correct 196 ms 25976 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1356 KB Output is correct
7 Correct 208 ms 26016 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 11 ms 1236 KB Output is correct
13 Correct 196 ms 25976 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -