# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93512 | psmao | Airline Route Map (JOI18_airline) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "airline.h"
#include <bits/stdc++.h>
using namespace std;
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;
void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}
bool g[1000][1000], cs[1001];
bool G[1001][1001];
int deg[1001], id[1001];
queue<int> Q;
struct pre{int x, y;}gao[3001*3001], gao2[3001*3001];
void Alice(int N, int M, int A[], int B[]) {
// InitG(N + 1, M);
int cnt = 0;
fo(i,0,M-1)
{
if(A[i] > B[i]) swap(A[i], B[i]);
gao[++cnt] = (struct pre){A[i], B[i]};
G[A[i]][B[i]] = true;
}
fo(i,0,N-2) if(!G[i][i+1])
{
gao[++cnt] = (struct pre){i, i+1};
// MakeG(i, i+1);
gao[++cnt] = (struct pre){i, N};
// MakeG(i, N);
}
gao[++cnt] = (struct pre){N-1, N};
// MakeG(N-1, N);
InitG(N + 1, cnt);
fo(i,1,cnt)
MakeG(i-1, gao[i].x, gao[i].y);
}
void Bob(int V, int U, int C[], int D[]) {
memset(G,false,sizeof(G));
fo(i,0,U-1) deg[C[i]] ++, G[D[i]][C[i]] = true;
int N;
fo(i,0,V-1) if(!deg[i]) Q.push(i), N = i;
id[N] = V-1;
fo(i,0,U-1) if(D[i] == N) cs[C[i]] = 1;
while(!Q.empty())
{
int h = Q.front(); Q.pop();
fo(i,0,V-1) if(G[h][i])
{
-- deg[i];
if(!deg[i])
{
id[i] = id[h]-1;
Q.push(i);
}
}
}
int cnt = 0;
fo(i,0,V-1) if(i != N) fo(j,0,V-1) if(j != N && G[i][j])
{
if(id[i] - 1 == id[j] && cs[j] == 1) continue;
// MakeMap(id[i], id[j]);
gao2[++cnt] = (struct pre){id[i], id[j]};
}
InitMap(V-1, cnt);
fo(i,1,cnt) MakeMap(gao2[i].x, gao2[i].y);
}