__hjwucj__ @ 2024-07-10 21:16:49
#include <bits/stdc++.h>
#define int long long
#define double long double
#define elif else if
#define fin(x) freopen (x,"r",stdin)
#define fout(x) freopen (x,"w",stdout)
#define rnt register int
#define reg(i,x,y) for (register int i=(x);i<=(y);++i)
#define Reg(i,x,y) for (register int i=(y);i>=(x);--i)
using namespace std;
namespace rwm {inline int read () {int s=0,w=0;char c=getchar ();while (!isdigit (c)){w|=(c=='-');c=getchar ();}while (isdigit (c)) {s=(s<<1)+(s<<3)+(c^48);c=getchar ();}return w?-s:s;}inline void write (int x) {if (x<0) putchar ( '-'),x=-x;if (x>9) write (x/10);putchar (x%10|48);}inline void writesp (int x) {write (x),putchar (' ');}inline void writeln (int x) {write (x),putchar ('\n');}inline int square (int x) {return x*x;}inline int floor (double x) {return x;}inline int ceil (double x) {return (int)(x+0.5);}inline int gcd (int x,int y) {int z=x%y;while (z) x=y,y=z,z=x%y;return y;}inline int lcm (int x,int y) {return x/gcd (x,y)*y;}};
using namespace rwm;
int n,s[101];
vector<int> a[101],data;
unordered_map<int,bool> ma[101];
bool b[101];
signed main ()
{
n=read ();
reg (i,1,n)
{
int t;
while ((t=read ())!=0) a[i].push_back (t),ma[i][t]=true;
s[i]=a[i].size ();
}
queue<int> q;
reg (i,1,n)
if (a[i].empty ()) q.push (i),b[i]=true;
while (!q.empty ())
{
int p=q.front ();q.pop ();
reg (i,1,n)
{
if (ma[i][p]) ma[i][p]=false,--s[i];
if (!s[i]&&!b[i]) b[i]=true,q.push (i);
}
data.push_back (p);
writesp (p);
}
// putchar ('\n');
// Reg (i,0,data.size ()-1) writesp (data[i]);
return 0;
}
by __hjwucj__ @ 2024-07-10 21:19:47
现已解决。此帖结。