# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
68856 | 2018-08-18T20:03:41 Z | duality | Amusement Park (JOI17_amusement_park) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pii> vpii; #include "Joi.h" static int parent[10000]; int find(int n) { if (parent[n] != n) parent[n] = find(parent[n]); return parent[n]; } static vi adjList[10000]; static int key[10000],nxt[10000]; static int message[10000]; static int doDFS(int u,int p) { int i; int m = 0,mv = -1; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if (v != p) { int r = doDFS(v,u); if (r+1 > m) m = r+1,mv = v; } } nxt[u] = mv; if (m == 60) { key[u] = 1; return 0; } else return m; } static int num = 0; static int doDFS2(int u,int p,LLI X) { int i; if (num < 60) { MessageBoard(u,((X & (1LL << num)) > 0)); message[u] = 1; } num++; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if (v != p) doDFS2(v,u,X); } return 0; } void Joi(int N,int M,int A[],int B[],long long int X,int T) { int i; for (i = 0; i < N; i++) parent[i] = i; for (i = 0; i < M; i++) { int pa = find(A[i]),pb = find(B[i]); if (pa != pb) { parent[pa] = pb; adjList[A[i]].pb(B[i]); adjList[B[i]].pb(A[i]); } } int j,f = 0; doDFS(0,-1); /*for (i = 0; i < N; i++) { if (key[i]) { int u = i; for (j = 0; j < 60; j++) { MessageBoard(u,((X & (1LL << j)) > 0)); message[u] = 1; u = nxt[u]; } f = 1; } }*/ f = 0; if (!f) doDFS2(0,-1,X); for (i = 0; i < N; i++) { if (!message[i]) MessageBoard(i,0); } }