Forum rules
- Ask questions about or share code from languages other than Source Engine scripting.
- Start new topic titles with the code language in brackets (i.e. [C#], [C++], [PHP], etc.)
public class QuickF
{ public static void main(String[] args)
{ int N = Integer.parseInt(args[0]);
int id[] = new int[N];
for (int i = 0; i < N ; i++) id[i] = i;
for( In.init(); !In.empty(); )
{ int p = In.getInt(), q = In.getInt();
int t = id[p];
if (t == id[q]) continue;
for (int i = 0; i < N; i++)
if (id[i] == t) id[i] = id[q];
Out.println(" " + p + " " + q);
}
}
}
-----
int i, j, p = In.getInt(), q = In.getInt();
for (i = p; i != id[i]; i = id[i]);
for (j = q; j != id[j]; j = id[j]);
if (i == j) continue;
id[i] = j;
Out.println(" " + p + " " + q);
-----
public class QuickUW
{ public static void main(String[] args)
{ int N = Integer.parseInt(args[0]);
int id[] = new int[N], sz[] = new int[N];
for (int i = 0; i < N ; i++)
{ id[i] = i; sz[i] = 1; }
for(In.init(); !In.empty(); )
{ int i, j, p = In.getInt(), q = In.getInt();
for (i = p; i != id[i]; i = id[i]);
for (j = q; j != id[j]; j = id[j]);
if (i == j) continue;
if (sz[i] < sz[j])
{ id[i] = j; sz[j] += sz[i]; }
else { id[j] = i; sz[i] += sz[j]; }
Out.println(" " + p + " " + q);
}
}
}
-----
for (i = p; i != id[i]; i = id[i])
id[i] = id[id[i]];
for (j = q; j != id[j]; j = id[j])
id[j] = id[id[j]];
static int search(int a[], int v, int l, int r)
{ int i;
for (i = l; i <= r; i++)
if (v == a[i]) return i;
return -1;
}
-----
static int search(int a[], int v, int l, int r)
{
while (r >= l)
{ int m = (l+r)/2;
if (v == a[m]) return m;
if (v < a[m]) r = m-1; else l = m+1;
}
return -1;
}
MAMALUIGI wrote:doodle ninja is like a newfag that stays a newfag forever. Ive been reading retarded topics and replies from this guy for about 6 months.
Well you obviously haven't been reading enough. Don't comment on month-old threads.
Just for the record: I agree with you.