Killed
Killed
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int dot,side,DOT1,DOT2,test;
while(cin>>dot>>side){
int flag[dot]={0};
test=0;
for(int a=1;a<=side;a++){
cin>>DOT1>>DOT2;
flag[DOT1-1]++,flag[DOT2-1]++;
}
if( (flag[0]%2==0&&flag[dot-1]%2==1) || (flag[0]%2==1&&flag[dot-1]%2==0) ){ //測頭尾
cout<<"NO\n";
continue;
}
for(int a=1;a<=dot-2;a++){ //測中間
if(flag[a]%2==1){
test=1;
break;
}
}
if(test){
cout<<"NO\n";
}else{
cout<<"YES\n";
}
}
}
改用 scanf 進行輸入
我改成scanf,printf後,反而全TLE了,我對scanf,printf不熟,請問有什麼錯誤的地方嗎?
有更動的地方已紅色字體標示
#include <stdio.h>
using namespace std;
int main(){
int dot,side,DOT1,DOT2,test;
while(scanf("%d%d",&dot,&side)){
int flag[dot]={0};
test=0;
for(int a=1;a<=side;a++){
scanf("%d%d",&DOT1,&DOT2);
flag[DOT1-1]++,flag[DOT2-1]++;
}
if( (flag[0]%2==0&&flag[dot-1]%2==1) || (flag[0]%2==1&&flag[dot-1]%2==0) ){
printf("%s\n","NO");
continue;
}
for(int a=1;a<=dot-2;a++){
if(flag[a]%2==1){
test=1;
break;
}
}
if(test){
printf("%s\n","NO");
}else{
printf("%s\n","YES");
}
}
}
https://zerojudge.tw/UserGuide.jsp#compiler
改用 scanf 進行輸入
我改成scanf,printf後,反而全TLE了,我對scanf,printf不熟,請問有什麼錯誤的地方嗎?
有更動的地方已紅色字體標示
#include
using namespace std;
int main(){
int dot,side,DOT1,DOT2,test;
while(scanf("%d%d",&dot,&side)!=EOF){
int flag[dot]={0};
test=0;
for(int a=1;a<=side;a++){
scanf("%d%d",&DOT1,&DOT2);
flag[DOT1-1]++,flag[DOT2-1]++;
}
if( (flag[0]%2==0&&flag[dot-1]%2==1) || (flag[0]%2==1&&flag[dot-1]%2==0) ){
printf("%s\n","NO");
continue;
}
for(int a=1;a<=dot-2;a++){
if(flag[a]%2==1){
test=1;
break;
}
}
if(test){
printf("%s\n","NO");
}else{
printf("%s\n","YES");
}
}
}