def solve():
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
a = list(map(int, input().split()))
pre = [0 for _ in range(n + 1)]
res = [0 for _ in range(n)]
for i in range(n):
pre[a[i]] = i
def check(v, r):
for x in a:
if x - 1 == r:
continue
if x < v:
return 0
elif x == v:
return 1
for i in range(n):
for x in f[i]:
if x - 1 == i:
continue
if check(x, i):
res[i] = x
break
for i in res:
print(i, end=" ")
if __name__ == "__main__":
_ = 1
while _:
solve()
_ -= 1
//jiudge: 21793: 1683635347
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[305][305],f[305],k,n,b[305],t[305];
signed main(){
cin >> n;
for (int i=1;i<=n;++i) {
for (int j=1;j<=n;++j) {
cin >> a[i][j];
}
}
for (int i=1;i<=n;++i) {
cin >> b[i];
t[b[i]]=i;
}
for (int i=1;i<=n;++i) {
t[0]=n+1;k=0;
for (int j=1;j<=n;++j) f[j]=0;
for (int j=1;j<=n;++j) {
if (j==i) continue;
if (t[j]<t[k]) {
k=j;
}
f[k]=1;
}
for (int j=1;j<=n;++j) {
if (f[a[i][j]]&&a[i][j]!=i) {
cout << a[i][j] << " ";
break;
}
}
}
}
//at most one straight through how many circles
1389B - Array Walk | 71B - Progress Bar |
701A - Cards | 545A - Toy Cars |
1538E - Funny Substrings | 234A - Lefthanders and Righthanders |
1611D - Weights Assignment For Tree Edges | 197A - Plate Game |
1474A - Puzzle From the Future | 6B - President's Office |
1405B - Array Cancellation | 431C - k-Tree |
101A - Homework | 1642C - Great Sequence |
1523B - Lord of the Values | 1406C - Link Cut Centroids |
2409. Count Days Spent Together | 2410. Maximum Matching of Players With Trainers |
1604C - Di-visible Confusion | 997A - Convert to Ones |
218A - Mountain Scenery | 486B - OR in Matrix |
1405A - Permutation Forgery | 1733A - Consecutive Sum |
1733B - Rule of League | 1733C - Parity Shuffle Sorting |
1264A - Beautiful Regional Contest | 1695A - Subrectangle Guess |
467B - Fedor and New Game | 252C - Points on Line |