結果

問題 No.241 出席番号(1)
ユーザー kou6839kou6839
提出日時 2015-08-10 17:22:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,970 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 79,740 KB
実行使用メモリ 59,060 KB
最終ジャッジ日時 2023-09-25 07:54:50
合計ジャッジ時間 11,686 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 127 ms
55,964 KB
testcase_06 WA -
testcase_07 AC 123 ms
55,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 126 ms
55,728 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 125 ms
55,704 KB
testcase_17 AC 128 ms
55,712 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 166 ms
56,932 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.prefs.BackingStoreException;

import javax.swing.text.Highlighter.Highlight;

class MaximumFlow {
	public ArrayList<Edge>[] G;
	private boolean[] used;
	
	public class Edge{
		int to;
		int cap;
		int rev;
		
		public Edge(int to,int cap, int rev){
			this.to = to;
			this.cap = cap;
			this.rev = rev;
		}
	}
	
	public MaximumFlow(int v){
		used = new boolean[v];
		G = new ArrayList[v];
		for(int i=0;i<v;i++){
			G[i]=new ArrayList<>();
		}
	}	
	
	public void addEdge(int from,int to, int cap){
		G[from].add(new Edge(to, cap, G[to].size()));
		G[to].add(new Edge(from, 0, G[from].size()-1));
	}
	
	private int dfs(int v, int t, int f){
		if(v==t) return f;
		used[v]=true;
		for(int i=0;i<G[v].size();i++){
			Edge edge = G[v].get(i);
			
			if(!used[edge.to] && edge.cap>0){
				int d = dfs(edge.to,t,Math.min(f,edge.cap));
				
				if(d>0){
					edge.cap-=d;
					G[edge.to].get(edge.rev).cap += d;
					return d;
				}
			}
		}
		
		return 0;
	}
	
	public int maxFlow(int s,int t){
		int flow = 0;
		for(;;){
			Arrays.fill(used, false);
			int f = dfs(s, t, Integer.MAX_VALUE);
			
			if(f==0) return flow;
			flow+=f;
		}
	}
}
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ng = new int[n];
		for(int i=0;i<n;i++) ng[i]=sc.nextInt();
		MaximumFlow mf = new MaximumFlow(2*n+2);
		for(int i=1;i<=n;i++){
			mf.addEdge(0, i, 1);
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(ng[i]!=j){
					mf.addEdge(i+1, j+n+1, 1);
				}
			}
		}
		for(int i=n+1;i<=2*n;i++){
			mf.addEdge(i, 2*n+1, 1);
		}
		int a = mf.maxFlow(0, 2*n+1);
		if(a != n ){
			System.out.println(-1);
		}else{
			t:for(int i=0;i<n;i++){
				for(int j=0;j<mf.G[i].size();j++){
					if(mf.G[i].get(j).cap==0){
						System.out.println(j);
						continue t;
					}
				}
			}
		}
		
	}
}
0