想請問這裡為什麼會有TLE的問題 ?
#include <iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
bool isODD[10005] = {false};
int d, l, sum = 0;
while(cin >> d >> l){
for(int i = 0; i < l; ++i){
int t1, t2;
cin >> t1 >> t2;
isODD[t1] = !isODD[t1];
isODD[t2] = !isODD[t2];
}
for(int i = 1; i <= d; ++i){
if(isODD[i]){
sum++;
if(sum > 2){
break;
}
}
}
if(sum == 2 || sum == 0){
cout << "YES" << '\n';
}
else{
cout << "NO" << '\n';
}
}
}
想請問這裡為什麼會有TLE的問題 ?
#include
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
bool isODD[10005] = {false};
int d, l, sum = 0;
while(cin >> d >> l){
for(int i = 0; i < l; ++i){
int t1, t2;
cin >> t1 >> t2;
isODD[t1] = !isODD[t1];
isODD[t2] = !isODD[t2];
}
for(int i = 1; i <= d; ++i){
if(isODD[i]){
sum++;
if(sum > 2){
break;
}
}
}
if(sum == 2 || sum == 0){
cout << "YES" << '\n';
}
else{
cout << "NO" << '\n';
}
}
}
可以用getchar_unlocked()做輸入,我用這個AC (0.1s)