Submission #1081382

# Submission time Handle Problem Language Result Execution time Memory
1081382 2024-08-30T03:07:18 Z thelegendary08 The Ties That Guide Us (CEOI23_incursion) C++17
12 / 100
230 ms 8292 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])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);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 776 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 194 ms 7872 KB Partially correct
2 Partially correct 215 ms 8068 KB Partially correct
3 Partially correct 109 ms 8032 KB Partially correct
4 Partially correct 83 ms 8028 KB Partially correct
5 Partially correct 186 ms 8056 KB Partially correct
6 Partially correct 73 ms 7784 KB Partially correct
7 Partially correct 70 ms 7964 KB Partially correct
8 Partially correct 193 ms 7876 KB Partially correct
9 Partially correct 199 ms 8068 KB Partially correct
10 Partially correct 136 ms 7892 KB Partially correct
11 Partially correct 91 ms 8092 KB Partially correct
12 Partially correct 226 ms 8048 KB Partially correct
13 Partially correct 79 ms 7888 KB Partially correct
14 Partially correct 82 ms 7988 KB Partially correct
15 Partially correct 206 ms 8284 KB Partially correct
16 Partially correct 202 ms 8060 KB Partially correct
17 Partially correct 114 ms 8132 KB Partially correct
18 Partially correct 91 ms 7780 KB Partially correct
19 Partially correct 148 ms 7772 KB Partially correct
20 Partially correct 76 ms 8036 KB Partially correct
21 Partially correct 77 ms 7960 KB Partially correct
22 Partially correct 200 ms 8064 KB Partially correct
23 Partially correct 212 ms 8028 KB Partially correct
24 Partially correct 91 ms 7864 KB Partially correct
25 Partially correct 88 ms 7772 KB Partially correct
26 Partially correct 75 ms 8096 KB Partially correct
27 Partially correct 72 ms 8020 KB Partially correct
28 Partially correct 77 ms 8032 KB Partially correct
29 Partially correct 199 ms 7884 KB Partially correct
30 Partially correct 207 ms 7920 KB Partially correct
31 Partially correct 81 ms 7844 KB Partially correct
32 Partially correct 225 ms 8128 KB Partially correct
33 Partially correct 224 ms 8292 KB Partially correct
34 Partially correct 81 ms 7776 KB Partially correct
35 Partially correct 74 ms 7868 KB Partially correct
36 Partially correct 210 ms 8096 KB Partially correct
37 Partially correct 199 ms 7780 KB Partially correct
38 Partially correct 230 ms 8044 KB Partially correct
39 Partially correct 154 ms 7952 KB Partially correct
40 Partially correct 210 ms 8032 KB Partially correct
41 Partially correct 75 ms 8032 KB Partially correct
42 Partially correct 68 ms 8016 KB Partially correct
43 Partially correct 194 ms 7876 KB Partially correct
44 Partially correct 222 ms 8020 KB Partially correct
45 Partially correct 90 ms 7952 KB Partially correct
46 Partially correct 77 ms 8020 KB Partially correct
47 Partially correct 97 ms 7872 KB Partially correct
48 Partially correct 75 ms 7836 KB Partially correct
49 Partially correct 76 ms 7836 KB Partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 8024 KB Not correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 776 KB Partially correct
2 Partially correct 194 ms 7872 KB Partially correct
3 Partially correct 215 ms 8068 KB Partially correct
4 Partially correct 109 ms 8032 KB Partially correct
5 Partially correct 83 ms 8028 KB Partially correct
6 Partially correct 186 ms 8056 KB Partially correct
7 Partially correct 73 ms 7784 KB Partially correct
8 Partially correct 70 ms 7964 KB Partially correct
9 Partially correct 193 ms 7876 KB Partially correct
10 Partially correct 199 ms 8068 KB Partially correct
11 Partially correct 136 ms 7892 KB Partially correct
12 Partially correct 91 ms 8092 KB Partially correct
13 Partially correct 226 ms 8048 KB Partially correct
14 Partially correct 79 ms 7888 KB Partially correct
15 Partially correct 82 ms 7988 KB Partially correct
16 Partially correct 206 ms 8284 KB Partially correct
17 Partially correct 202 ms 8060 KB Partially correct
18 Partially correct 114 ms 8132 KB Partially correct
19 Partially correct 91 ms 7780 KB Partially correct
20 Partially correct 148 ms 7772 KB Partially correct
21 Partially correct 76 ms 8036 KB Partially correct
22 Partially correct 77 ms 7960 KB Partially correct
23 Partially correct 200 ms 8064 KB Partially correct
24 Partially correct 212 ms 8028 KB Partially correct
25 Partially correct 91 ms 7864 KB Partially correct
26 Partially correct 88 ms 7772 KB Partially correct
27 Partially correct 75 ms 8096 KB Partially correct
28 Partially correct 72 ms 8020 KB Partially correct
29 Partially correct 77 ms 8032 KB Partially correct
30 Partially correct 199 ms 7884 KB Partially correct
31 Partially correct 207 ms 7920 KB Partially correct
32 Partially correct 81 ms 7844 KB Partially correct
33 Partially correct 225 ms 8128 KB Partially correct
34 Partially correct 224 ms 8292 KB Partially correct
35 Partially correct 81 ms 7776 KB Partially correct
36 Partially correct 74 ms 7868 KB Partially correct
37 Partially correct 210 ms 8096 KB Partially correct
38 Partially correct 199 ms 7780 KB Partially correct
39 Partially correct 230 ms 8044 KB Partially correct
40 Partially correct 154 ms 7952 KB Partially correct
41 Partially correct 210 ms 8032 KB Partially correct
42 Partially correct 75 ms 8032 KB Partially correct
43 Partially correct 68 ms 8016 KB Partially correct
44 Partially correct 194 ms 7876 KB Partially correct
45 Partially correct 222 ms 8020 KB Partially correct
46 Partially correct 90 ms 7952 KB Partially correct
47 Partially correct 77 ms 8020 KB Partially correct
48 Partially correct 97 ms 7872 KB Partially correct
49 Partially correct 75 ms 7836 KB Partially correct
50 Partially correct 76 ms 7836 KB Partially correct
51 Incorrect 67 ms 8024 KB Not correct
52 Halted 0 ms 0 KB -