I think of "N<=50" as "N,M<=50". Actually M<=N*(N-1)/2. It's a stupid mistake but it took me so much time to check out TAT (btw, the point to solve the question is GCD(x,x+1)=1, it can be proved that the answer is always "YES". 4 4 1 2 2 3 3 1 1 4
One possible answer is: YES 1 2 3 4 Thank you a lot, this problem took me so much time When I make my algo work for not connected graphs, i got AC. (I changed dfs(0) to for(int i=0;i<n;++i)if(!lev[i])dfs(i); ) i got AC but my code is correct when is graph is connect, who can solve this when the graph is arbitary? plz give me your code. (sorry for bad english) :D This problem is so easy ^^! Who can tell me? I have WA1. Thanks a lot. Edited by author 03.05.2009 09:55 Edited by author 03.05.2009 09:56 Edited by moderator 13.05.2009 01:51 "If there are several flights that depart from one airport then the greatest common divisor of their flight numbers should be equal to 1." input 6 6 1 2 2 3 2 4 4 3 5 6 4 5 output 1 2 4 6 5 3 This output isn't correct because for second flight (2, 3) gcd is equal to 2 != 1. Edited by moderator 13.05.2009 01:52 O_o "If there are several FLIGHTS that depart from one AIRPORT then the greatest common divisor of their flight numbers should be equal to 1." Why did you calculate gcd for the second flight? Output is a numbers of flights, not numbers of flights. May be you should do this for the second airport. However gcd of the flight numbers of the second airport is gcd(1,2,4) = 1. P.S. I think output is not right because gcd of the flight numbers from the airport #3 is equal to 2. Edited by author 22.07.2010 10:00 Bad test #13 has been corrected, solutions that had troubles with this test have been rejudged. 23 authors have got AC. Yes. Get a chain, paint it CUR...CUR+X. That's not everything, but a good start to get fair AC in 0.001 sec. I can find any polynomial algorithm but use some logics(AC). Can somebody tell normal algorithm. My mail piratic@mail.ru find the way from one to all airports and each airport can be passed one time Edited by author 24.05.2008 19:16 No, just think a bit - and you'll find more beautiful solution... Sorry, my english is too poor to describe my algo. But here is a little tips: For any neighbor positive integers a & b: GCD(a,b)=1 I.E. GCD(1,2)=1 GCD(2,3)=1 GCD(3,4)=1 GCD(4,5)=1 GCD(5,6)=1 GCD(6,7)=1 GCD(7,8)=1 GCD(8,9)=1 GCD(9,10)=1 ...... See this: 6 6 1 2 2 3 3 1 4 5 5 6 6 4 The answer is NO But there are no data like this... I got AC although my program always prints "YES"... is there an algo wich works in O(n+m) for disconnected graphs too? I think no. For exmaple, sometimes answer is NO and strategy 1,2,3,4... doesn't work. When statements were incorrect (it was not said that graph is connected) I and some my friends tried to solve it... but we couldn't find even polynomial solution. So I think no. If graph is connected ( current statement ), problem can be solved by dividing graph into chains ( like in #1441 ), chains are: k,k+1,...,l . This solution is absolutely correct. No, I think the answer is 3 4 1 2 6 5 Sorry,I think your answer is wrong. See the node 5:the number of one egde is 2,another is 6,gcd(2,6)=2<>1 I think we can get the answer in O(n+m)... Just use the method you mentioned... Each node has two arcs which numbered x and x+1... Please consider the Sample input and output : The 1st flight ( connects 1 and 2 ) and the 2-nd flight ( 2-3) are flights that depart from one airport ( airport 2 ) ( The flight are 2 directions flight ) . But the sample output indicates that their numbers are 4 and 2 , so their greatest common divisor can't be 1 as the problem description ! I don't know if I wrong . I got WA too . Please explain for me Thanks a lot ! . You must calculate greatest common divisor of all flights, that departs from one airport. For airport 2 this numbers are 2,3,4 and there greatest common divisor is 1. Why cant we just output first M prime numbers??? WA1 #include<stdio.h> #include<math.h> void main() {int n,h; bool f; scanf("%i%i",&n,&n); printf("YES\n1"); for(int i=2,j=1;j<n;i++) {h=(int)sqrt((float)i); f=0; for(int k=2;k<=h;k++) if((i%k)==0) {f=1;break;} if(!f){printf(" %i",i);j++;} } } Because numbers must be [1..M] AC!!!!! Edited by author 06.08.2008 18:53 Validator was updated and some new tests were added. Many authors got WA and TL because their heuristics failed new tests. Try to find new tricky tests if your heuristics still has AC. Does your solution can pass ALL kinds of tests under this constraints? 6 5 1 2 2 4 4 3 5 6 3 2 Is the answer YES 4 1 2 5 3 right? I've got AC. The problem is very strange. I initial the numbers(give every edge a number), and got AC at last. It took me a long time! The graph is not connected. Incorrect.Sine dubitatibus. some submissions since 20-Feb-2006 have been rejudged and got AC Edited by author 26.05.2006 01:31 Can someone post test 6? Thanks Please, explain me why answer is always YES? It's right only for connected graphs! For example: 6 6 1 2 2 3 3 1 4 5 5 6 6 4 Answer is NO. Oh, what a trick! I was very much confused seeing > 400 people who solved this problem. I'm really annoyed beacuse in this case the problem is O(n + m) using a simple idea gcd(n,n + 1) = 1. But if the graph can be disconnected everything is much worse!!! Graph can be disonnected. Sample is. But testset is weak... Why am I not surprised :) My always "YES" program got AC. With such tests the problem is much easier than it is. Please, change tests or statements! Graph is always connected now. Statements and tests are updated. So, the solution always exists. |
|