답안 #233080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233080 2020-05-19T09:00:56 Z crossing0ver 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
0 / 100
7 ms 4352 KB
#include<bits/stdc++.h>
#include "gardenlib.h"
using namespace std;

pair<int,int> D[150001][31][2];
pair<int,int> mn[150001][2];

vector<pair<int,int>> adj[150001];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
	P++;
	for (int i = 0; i < M; i++) {
		R[i][0]++;
		R[i][1]++;
		adj[R[i][0]].push_back({R[i][1],i + 1});
		adj[R[i][1]].push_back({R[i][0],i+1});
	}
	for (int i = 1; i <= N; i++) {
		 if (adj[i].size() == 1) mn[i][0] = {adj[i][0].second,adj[i][0].first}, mn[i][1] = {adj[i][0].second,adj[i][0].first};
		else mn[i][0] = {adj[i][0].second,adj[i][0].first}, mn[i][1] = {adj[i][1].second,adj[i][1].first};
	}
	for (int i = 1; i <= N; i++) {
		D[i][0][0] = {mn[i][0].second,mn[i][0].first};
		D[i][0][1] = {mn[i][1].second,mn[i][1].first};
	}
		for (int j = 1; j <= 30; j++) {
			for (int i = 1; i <= N; i++) {
				auto S = D[i][j-1][0];
				int x = S.first;
				int val = S.second;
				if (val == mn[x][0].first) {
					D[i][j][1] = D[x][j-1][1];
				}
				else D[i][j][0] = D[x][j-1][0];
				 S = D[i][j-1][1];
				 x = S.first;
				 val = S.second;
				if (val == mn[x][0].first) 
					D[i][j][1] = D[x][j-1][1];
				else D[i][j][0] = D[x][j-1][0];
			}
		}
	
    for (int q = 0,k; q < Q; q++) {
    	k = G[q];
    	pair<int,int> cur;
    	int ans  = 0;
    	for (int i = 1; i <= N; i++) {
    		 cur = {i,0};
    	for (int j = 0; j <= 30; j++)
    	if (k & (1<< j) )
    		if (cur.second != mn[cur.first][0].first)
    			cur = D[cur.first][j][0];
    		else cur = D[cur.first][j][1];
    	if (cur.first == P) ans ++;	
    	}
        answer(ans);
    }
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:50:9: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
      if (k & (1<< j) )
         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4352 KB Output isn't correct
2 Halted 0 ms 0 KB -