답안 #1081383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081383 2024-08-30T03:10:57 Z thelegendary08 The Ties That Guide Us (CEOI23_incursion) C++17
12 / 100
284 ms 8288 KB
#include <bits/stdc++.h>
#include "incursion.h"
#define f0r(i,n) for(int i = 0;i<n;i++)
#define vi vector<int>
using namespace std;
std::vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {

    safe--;
	int n;

	int two;
	n = F.size() + 1;
	vector<int>dist(n);
	dist[safe] = 0;
	vector<int>adj[n];
	vi deg(n, 0);
	vi degcnt(4, 0);
	f0r(i, n-1){
		adj[--F[i].first].push_back(--F[i].second);
		adj[F[i].second].push_back(F[i].first);
		deg[F[i].first]++;
		deg[F[i].second]++;
	}
	//f0r(i,n)cout<<deg[i]<<' ';
	//cout<<'\n';

	f0r(i,n){
	    if(deg[i] == 2)two = i;
        degcnt[deg[i]]++;
	}

	if(degcnt[3] == 0){
        vi col(n, 0);
        queue<int>q;
        q.push(safe);
        vector<bool>vis(n,0);
        vis[safe] = 1;

        col[safe] = 0;
        while(!q.empty()){
            int cur = q.front();
            q.pop();
            for(auto u : adj[cur]){
                if(vis[u])continue;
                vis[u] = 1;
                dist[u] = dist[cur] + 1;
                col[u] = (col[cur] + 1) % 3;
                q.push(u);
            }
        }
        return col;
	}
	else{
	    vi col(n,0);
        vi par(n);
        par[two] = -1;
        queue<int>q;
        q.push(two);
        while(!q.empty()){
            int cur = q.front();
            q.pop();
            for(auto u : adj[cur]){
                if(u != par[cur]){
                    par[u] = cur;
                    q.push(u);
                }
            }
        }
        //f0r(i,n)cout<<par[i]<<' ';
        //cout<<'\n';

        int now = safe;
        while(now != -1){
            //cout<<now<<'\n';
            col[now] = 1;
            now = par[now];
        }
        //cout<<cur<<'\n';
        //cout<<par[cur]<<'\n';

        //cout<<par[par[par[cur]]]<<'\n';
        return col;


	}


}

void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
	int x;
	vector<int>nxt = {2, 0, 1};
	int n = F.size() + 1;
	vector<bool>vis(n+1, 0);
	vector<int>adj[n+1];
	vi deg(n+1);
	vi degcnt(4, 0);
	f0r(i, n-1){
		adj[F[i].first].push_back(F[i].second);
		adj[F[i].second].push_back(F[i].first);
		deg[F[i].first]++;
		deg[F[i].second]++;
	}
	int two;
	for(int i = 1; i<=n; i++){
        if(deg[i]==2)two = i;
        degcnt[deg[i]]++;
	}
	if(degcnt[3] == 0){
        vis[curr] = 1;
        //queue<int>q;
        //q.push(curr);
        bool found = false;
        int col = t;
        int cur = curr;
        vi cols(n+1, -1);
        cols[curr] = t;
        while(!found){
            bool ok = 0;
            for(auto u : adj[cur]){
                if(vis[u])continue;
                vis[u] = 1;
                x = visit(u);
                cols[u] = x;
                if(x == nxt[cols[cur]]){
                    cur = u;
                    ok = 1;
                    break;
                }
                else{
                    visit(cur);
                }
            }
            if(!ok)return;
        }
	}
	else{
        vi par(n+1);
        par[two] = -1;
        queue<int>q;
        q.push(two);
        while(!q.empty()){
            int cur = q.front();
            q.pop();
            for(auto u : adj[cur]){
                if(u != par[cur]){
                    par[u] = cur;
                    q.push(u);
                }
            }
        }
        vi vis(n+1, 0);
        int cur = curr;
        int col = t;
        int x;
        vis[cur] = 1;
        while(col == 0){
            cur = par[cur];
            vis[cur] = 1;
            x = visit(cur);
            col = x;
        }
        bool found = 0;
        while(!found){
            vector<pair<int,int>>thing;
            for(auto u : adj[cur]){
                if(!vis[u] && u != par[cur])thing.push_back({deg[u], u});
            }
            sort(thing.rbegin(), thing.rend());
            bool ok =0;
            for(auto u : thing){
                x = visit(u.second);
                if(x == 0){
                    visit(cur);
                }
                else{
                    cur = u.second;
                    vis[cur] = 1;
                    col = x;
                    ok = 1;
                    break;
                }
            }
            if(!ok)return;
        }

	}



}

Compilation message

incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:114:13: warning: unused variable 'col' [-Wunused-variable]
  114 |         int col = t;
      |             ^~~
interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 764 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 207 ms 8132 KB Partially correct
2 Partially correct 198 ms 8140 KB Partially correct
3 Partially correct 96 ms 7840 KB Partially correct
4 Partially correct 104 ms 8100 KB Partially correct
5 Partially correct 179 ms 7988 KB Partially correct
6 Partially correct 82 ms 7836 KB Partially correct
7 Partially correct 74 ms 7952 KB Partially correct
8 Partially correct 216 ms 8060 KB Partially correct
9 Partially correct 208 ms 7868 KB Partially correct
10 Partially correct 129 ms 7876 KB Partially correct
11 Partially correct 96 ms 7872 KB Partially correct
12 Partially correct 278 ms 7872 KB Partially correct
13 Partially correct 73 ms 8028 KB Partially correct
14 Partially correct 76 ms 8012 KB Partially correct
15 Partially correct 193 ms 8064 KB Partially correct
16 Partially correct 208 ms 8072 KB Partially correct
17 Partially correct 122 ms 8116 KB Partially correct
18 Partially correct 86 ms 7836 KB Partially correct
19 Partially correct 163 ms 8064 KB Partially correct
20 Partially correct 78 ms 8028 KB Partially correct
21 Partially correct 76 ms 8032 KB Partially correct
22 Partially correct 215 ms 8072 KB Partially correct
23 Partially correct 198 ms 7872 KB Partially correct
24 Partially correct 82 ms 7880 KB Partially correct
25 Partially correct 93 ms 7836 KB Partially correct
26 Partially correct 84 ms 7736 KB Partially correct
27 Partially correct 71 ms 8040 KB Partially correct
28 Partially correct 72 ms 8288 KB Partially correct
29 Partially correct 207 ms 8048 KB Partially correct
30 Partially correct 203 ms 8280 KB Partially correct
31 Partially correct 83 ms 7948 KB Partially correct
32 Partially correct 214 ms 8060 KB Partially correct
33 Partially correct 245 ms 7864 KB Partially correct
34 Partially correct 66 ms 7772 KB Partially correct
35 Partially correct 75 ms 7964 KB Partially correct
36 Partially correct 225 ms 8044 KB Partially correct
37 Partially correct 208 ms 7876 KB Partially correct
38 Partially correct 284 ms 8020 KB Partially correct
39 Partially correct 150 ms 8128 KB Partially correct
40 Partially correct 180 ms 7872 KB Partially correct
41 Partially correct 83 ms 7860 KB Partially correct
42 Partially correct 74 ms 8032 KB Partially correct
43 Partially correct 200 ms 8092 KB Partially correct
44 Partially correct 205 ms 7868 KB Partially correct
45 Partially correct 77 ms 7844 KB Partially correct
46 Partially correct 87 ms 7764 KB Partially correct
47 Partially correct 80 ms 7876 KB Partially correct
48 Partially correct 75 ms 7780 KB Partially correct
49 Partially correct 79 ms 7764 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 8032 KB Correct
2 Incorrect 75 ms 8100 KB Not correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 764 KB Partially correct
2 Partially correct 207 ms 8132 KB Partially correct
3 Partially correct 198 ms 8140 KB Partially correct
4 Partially correct 96 ms 7840 KB Partially correct
5 Partially correct 104 ms 8100 KB Partially correct
6 Partially correct 179 ms 7988 KB Partially correct
7 Partially correct 82 ms 7836 KB Partially correct
8 Partially correct 74 ms 7952 KB Partially correct
9 Partially correct 216 ms 8060 KB Partially correct
10 Partially correct 208 ms 7868 KB Partially correct
11 Partially correct 129 ms 7876 KB Partially correct
12 Partially correct 96 ms 7872 KB Partially correct
13 Partially correct 278 ms 7872 KB Partially correct
14 Partially correct 73 ms 8028 KB Partially correct
15 Partially correct 76 ms 8012 KB Partially correct
16 Partially correct 193 ms 8064 KB Partially correct
17 Partially correct 208 ms 8072 KB Partially correct
18 Partially correct 122 ms 8116 KB Partially correct
19 Partially correct 86 ms 7836 KB Partially correct
20 Partially correct 163 ms 8064 KB Partially correct
21 Partially correct 78 ms 8028 KB Partially correct
22 Partially correct 76 ms 8032 KB Partially correct
23 Partially correct 215 ms 8072 KB Partially correct
24 Partially correct 198 ms 7872 KB Partially correct
25 Partially correct 82 ms 7880 KB Partially correct
26 Partially correct 93 ms 7836 KB Partially correct
27 Partially correct 84 ms 7736 KB Partially correct
28 Partially correct 71 ms 8040 KB Partially correct
29 Partially correct 72 ms 8288 KB Partially correct
30 Partially correct 207 ms 8048 KB Partially correct
31 Partially correct 203 ms 8280 KB Partially correct
32 Partially correct 83 ms 7948 KB Partially correct
33 Partially correct 214 ms 8060 KB Partially correct
34 Partially correct 245 ms 7864 KB Partially correct
35 Partially correct 66 ms 7772 KB Partially correct
36 Partially correct 75 ms 7964 KB Partially correct
37 Partially correct 225 ms 8044 KB Partially correct
38 Partially correct 208 ms 7876 KB Partially correct
39 Partially correct 284 ms 8020 KB Partially correct
40 Partially correct 150 ms 8128 KB Partially correct
41 Partially correct 180 ms 7872 KB Partially correct
42 Partially correct 83 ms 7860 KB Partially correct
43 Partially correct 74 ms 8032 KB Partially correct
44 Partially correct 200 ms 8092 KB Partially correct
45 Partially correct 205 ms 7868 KB Partially correct
46 Partially correct 77 ms 7844 KB Partially correct
47 Partially correct 87 ms 7764 KB Partially correct
48 Partially correct 80 ms 7876 KB Partially correct
49 Partially correct 75 ms 7780 KB Partially correct
50 Partially correct 79 ms 7764 KB Partially correct
51 Correct 80 ms 8032 KB Correct
52 Incorrect 75 ms 8100 KB Not correct
53 Halted 0 ms 0 KB -