Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
JAVA啊,你让我说你什么啊,我用SPFA写的跑了6S,汗。。。。Source Code Problem: 2983 User: yzhw Memory: 16960K Time: 6172MS Language: Java Result: Accepted Source Code import java.io.*; import java.util.*; public class Main { /** * @param args */ static int c=0; static int g[]=new int[1001]; static int next[]=new int[300000]; static int val[]=new int[300000]; static int v[]=new int[300000]; //static LinkedList<Integer> q=new LinkedList<Integer>(); static int n,m; static int count[]=new int[1001]; static int len[]=new int[1001]; static int s=-1,e=-1; static int q[]=new int[2000000]; static boolean empty() { return s==e&&s!=-1; } static void push(int pos) { q[++s]=pos; } static int pop() { return q[++e]; } static void insert(int s,int e,int value) { v[c]=e; next[c]=g[s]; val[c++]=value; g[s]=c-1; } static boolean chk() { Arrays.fill(count, 0); Arrays.fill(len, 0xfffffff); s=e=-1; count[0]++; push(0); len[0]=0; while(!empty()) { int top=pop(); for(int p=g[top];p!=-1;p=next[p]) if(len[v[p]]>len[top]+val[p]) { len[v[p]]=len[top]+val[p]; count[v[p]]++; push(v[p]); if(count[v[p]]>n+1) return false; } } return true; } public static void main(String[] args) throws IOException{ Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); while(in.hasNext()) { n=in.nextInt(); m=in.nextInt(); Arrays.fill(g, -1); c=0; for(int i=0;i<m;i++) { String jud=in.next(); if(jud.equals("P")) { int a=in.nextInt(),b=in.nextInt(),value=in.nextInt(); insert(a,b,-value); insert(b,a,value); } else { int a=in.nextInt(),b=in.nextInt(); insert(a,b,-1); } } for(int i=1;i<=n;i++) insert(0,i,0); if(chk()) System.out.println("Reliable"); else System.out.println("Unreliable"); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator